123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- <?php
- namespace app\api\controller\inspection;
- use app\api\controller\inspection\Base;
- use app\common\Service\InspectService;
- use app\common\Enum\StatusEnum;
- /**
- * 示例接口
- */
- class Index extends Base
- {
- /**
- * 获取验货选项列表
- */
- public function getOptions()
- {
- // 查询验货类型的
- $inspectId= $this->request->param('inspection_type_id');
- if(intval($inspectId) <= 0){
- $this->error('验货类型ID不能为空');
- }
- $params = [
- 'status' => StatusEnum::ENABLED,
- 'inspection_type_id' => $inspectId,
- ];
- $options = InspectService::getInspectionItems($params);
- $this->success('获取成功', $options);
- }
- /**
- * 提交验货任务
- *
- * @ApiTitle (提交验货任务)
- * @ApiSummary (提交验货任务,包含验货结果和照片信息)
- * @ApiMethod (POST)
- * @ApiRoute (/api/inspection/index/submitTask)
- * @ApiParams (name="order_id", type="integer", required=true, description="订单ID")
- * @ApiParams (name="order_goods_id", type="integer", required=true, description="订单商品ID")
- * @ApiParams (name="inspector_id", type="integer", required=true, description="验货员ID")
- * @ApiParams (name="remark", type="string", required=false, description="备注信息")
- * @ApiParams (name="images", type="string", required=false, description="任务图片,多张用逗号分隔")
- * @ApiParams (name="start_time", type="integer", required=false, description="任务开始时间戳")
- * @ApiParams (name="end_time", type="integer", required=false, description="任务结束时间戳")
- * @ApiParams (name="task_id", type="integer", required=false, description="任务ID,更新时传入")
- * @ApiParams (name="results", type="array", required=true, description="验货结果数组")
- * @ApiParams (name="results.item_id", type="integer", required=true, description="检查项ID")
- * @ApiParams (name="results.name", type="string", required=false, description="检查项名称")
- * @ApiParams (name="results.is_qualified", type="integer", required=true, description="是否合格 0:否 1:是")
- * @ApiParams (name="results.remark", type="string", required=false, description="不合格原因")
- * @ApiParams (name="results.photos", type="array", required=false, description="照片数组")
- * @ApiParams (name="results.photos.photo_url", type="string", required=true, description="照片URL")
- * @ApiReturnParams (name="code", type="integer", required=true, sample="1")
- * @ApiReturnParams (name="msg", type="string", required=true, sample="验货任务提交成功")
- * @ApiReturnParams (name="data", type="object", description="返回数据")
- * @ApiReturn ({
- 'code':'1',
- 'msg':'验货任务提交成功',
- 'data': {
- 'task_id': 123
- }
- })
- */
- public function submitTask()
- {
- $params = $this->request->post();
-
- // 验证必要参数
- if (empty($params['order_id'])) {
- $this->error('订单ID不能为空');
- }
-
- if (empty($params['order_goods_id'])) {
- $this->error('订单商品ID不能为空');
- }
-
- $params['inspector_id'] = $this->auth->id;
- if (empty($params['results']) || !is_array($params['results'])) {
- $this->error('验货结果不能为空');
- }
-
- // 组装任务数据
- $taskData = [
- 'order_id' => $params['order_id'],
- 'order_goods_id' => $params['order_goods_id'],
- 'inspector_id' => $params['inspector_id'],
- 'remark' => $params['remark'] ?? '',
- 'images' => $params['images'] ?? '',
- 'start_time' => $params['start_time'] ?? time(),
- 'end_time' => $params['end_time'] ?? time(),
- 'task_status' => 1, // 进行中
- 'status' => 1 // 开启
- ];
-
- // 如果是更新任务,传入task_id
- if (!empty($params['task_id'])) {
- $taskData['task_id'] = $params['task_id'];
- }
-
- // 组装结果数据
- $resultData = [];
- foreach ($params['results'] as $result) {
- if (empty($result['item_id'])) {
- $this->error('检查项ID不能为空');
- }
-
- $resultItem = [
- 'item_id' => $result['item_id'],
- 'name' => $result['name'] ?? '',
- 'is_qualified' => $result['is_qualified'] ?? 1,
- 'remark' => $result['remark'] ?? '',
- 'photos' => $result['photos'] ?? []
- ];
-
- $resultData[] = $resultItem;
- }
- $inspectUid = $this->auth->id;
- // 调用服务提交验货任务
- list($code, $msg, $data) = InspectService::submitInspectionTask($taskData, $resultData,$inspectUid);
-
- if ($code == 1) {
- $this->success($msg, $data);
- } else {
- $this->error($msg);
- }
- }
- //
- }
|