'require|checkId', 'pickup_code' => 'require|checkPickupCode', 'confirm' => 'require|in:0,1' ]; protected $message = [ 'pickup_code.require' => '参数缺失', 'confirm.require' => '参数缺失', 'confirm.in' => '参数错误', ]; public function sceneVerification() { return $this->only(['pickup_code','confirm']); } public function sceneVerificationConfirm() { return $this->only(['id']); } /** * @notes 检测订单是否可以核销 * @param $value * @param $rule * @param $data * @return bool|string * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @author ljj * @date 2021/8/27 5:19 下午 */ public function checkPickupCode($value,$rule,$data) { $result = Order::where(['pickup_code'=>$value])->find(); if (empty($result)) { return '提货码不正确'; } if ($result['order_status'] == OrderEnum::STATUS_CLOSE) { return '订单已关闭'; } if (! in_array($result['order_status'], [ OrderEnum::STATUS_WAIT_DELIVERY, OrderEnum::STATUS_WAIT_RECEIVE ])) { return '订单已不允许核销'; } if ($result['delivery_type'] != DeliveryEnum::SELF_DELIVERY) { return '不是自提订单,不允许核销'; } if ($result['verification_status'] == OrderEnum::WRITTEN_OFF) { return '订单已核销'; } if ($result['order_type'] == OrderEnum::TEAM_ORDER){ if ($result['is_team_success'] != TeamEnum::TEAM_FOUND_SUCCESS){ return '拼团成功后才能核销'; } } $verifier = SelffetchVerifier::where(['selffetch_shop_id'=>$result['selffetch_shop_id'],'user_id'=>$data['user_id'],'status'=>1])->find(); if (empty($verifier)) { return '非门店核销员,无法核销订单'; } $order_goods = OrderGoods::where(['order_id'=>$result['id']])->select()->toArray(); foreach ($order_goods as $goods) { $after_sale = AfterSale::where(['order_goods_id' => $goods['id'], 'order_id' => $goods['order_id']])->findOrEmpty(); if (!$after_sale->isEmpty() && $after_sale->status == AfterSaleEnum::STATUS_ING) { return '订单商品:'.$goods['goods_name'].' 处于售后中,无法核销'; } } return true; } /** * @notes 检查订单是否可以提货 * @param $value * @param $rule * @param $data * @return bool|string * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @author ljj * @date 2021/8/27 5:46 下午 */ public function checkId($value,$rule,$data) { $result = Order::findOrEmpty($value); if ($result->isEmpty()) { return '订单不存在'; } if (! in_array($result['order_status'], [ OrderEnum::STATUS_WAIT_DELIVERY, OrderEnum::STATUS_WAIT_RECEIVE ])) { return '订单已不允许核销'; } if ($result['delivery_type'] != DeliveryEnum::SELF_DELIVERY) { return '不是自提订单,不允许提货'; } if ($result['verification_status'] == OrderEnum::WRITTEN_OFF) { return '订单已核销'; } if ($result['order_type'] == OrderEnum::TEAM_ORDER){ if ($result['is_team_success'] != TeamEnum::TEAM_FOUND_SUCCESS){ return '拼团成功后才能提货'; } } $verifier = SelffetchVerifier::where(['selffetch_shop_id'=>$result['selffetch_shop_id'],'user_id'=>$data['user_id'],'status'=>1])->find(); if (empty($verifier)) { return '非门店核销员,无法核销订单'; } return true; } }