123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242 |
- <?php
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- namespace app\shopapi\validate;
-
-
- use app\common\basics\Validate;
- use app\common\enum\OrderEnum;
- use app\common\model\Delivery;
- use app\common\model\order\Order;
- use app\common\model\team\Team;
- use app\common\model\team\TeamJoin;
- use think\facade\Db;
-
-
- class OrderValidate extends Validate
- {
- protected $rule = [
- 'id' => 'require|checkId',
- 'consignee' => 'require',
- 'province' => 'require',
- 'city' => 'require',
- 'district' => 'require',
- 'address' => 'require',
- 'mobile' => [ 'require', 'checkMobile' => [ 'check' => [ 'land', 'hk' ] ] ],
- 'send_type' => 'require|in:1,2',
- 'shipping_id' => 'requireIf:send_type,1',
- 'invoice_no' => 'requireIf:send_type,1',
- ];
-
- protected $message = [
- 'id.require' => '参数缺失',
- 'consignee.require' => '请填写收件人',
- 'province.require' => '地址参数缺失',
- 'city.require' => '地址参数缺失',
- 'district.require' => '地址参数缺失',
- 'address.require' => '请填写详细',
- 'mobile.require' => '请填写手机号码',
- 'mobile.mobile' => '请填写正确的手机号码',
- 'send_type.require' => '请选择快递方式',
- 'send_type.in' => '快递方式参数错误',
- 'shipping_id.requireIf' => '请选择快递公司',
- 'invoice_no.requireIf' => '请填写快递单号',
- ];
-
- public function sceneDetail()
- {
- return $this->only(['id']);
- }
-
- public function sceneCancel()
- {
- return $this->only(['id'])
- ->append('id','checkCancel');
- }
-
- public function sceneDel()
- {
- return $this->only(['id'])
- ->append('id','checkDel');
- }
-
- public function sceneEditAddress()
- {
- return $this->only(['id','consignee','province','city','district','address','mobile']);
- }
-
- public function sceneDelivery()
- {
- return $this->only(['id','send_type','shipping_id','invoice_no'])
- ->append('id','checkDelivery');
- }
-
- public function sceneConfirm()
- {
- return $this->only(['id'])
- ->append('id','checkConfirm');
- }
-
- public function sceneLogistics()
- {
- return $this->only(['id'])
- ->append('id','checkLogistics');
- }
-
- public function sceneGetAddress()
- {
- return $this->only(['id']);
- }
-
-
-
- public function checkId($value,$rule,$data)
- {
- $result = Order::where(['id'=>$value,'shop_id'=>$data['shop_id'],'del'=>0,'delete'=>0])->findOrEmpty();
- if ($result->isEmpty()) {
- return '订单不存在';
- }
- return true;
- }
-
-
-
- public function checkCancel($value,$rule,$data)
- {
- $result = Order::where(['id'=>$value,'shop_id'=>$data['shop_id']])->findOrEmpty();
-
- if ($result['order_status'] > OrderEnum::ORDER_STATUS_DELIVERY && $result['delivery_type'] != 2) {
- return '此订单不可取消';
- }
-
- if ($result['order_status'] > OrderEnum::ORDER_STATUS_GOODS && $result['delivery_type'] == 2) {
- return '此订单不可取消';
- }
-
- if ($result['order_type'] == OrderEnum::TEAM_ORDER) {
- $found = Db::name('team_join')->where(['order_id' => $order['id']])->find();
- if ($found['status'] == Team::STATUS_WAIT_SUCCESS) {
- return '已支付的拼团订单需要有拼团结果才可以取消';
- }
- }
-
- return true;
- }
-
-
-
- public function checkDel($value,$rule,$data)
- {
- $result = Order::where(['id'=>$value,'shop_id'=>$data['shop_id']])->findOrEmpty();
- if ($result['order_status'] != OrderEnum::ORDER_STATUS_DOWN) {
- return '此订单不可删除';
- }
- return true;
- }
-
-
-
- public function checkDelivery($value,$rule,$data)
- {
- $result = Order::where(['id'=>$value])->findOrEmpty();
-
- if ($result['shipping_status'] == 1) {
- return '订单已发货';
- }
- if ($result['order_type'] == OrderEnum::TEAM_ORDER) {
- $join = TeamJoin::where(['order_id' => $result['id']])->findOrEmpty();
- if ($join['status'] != Team::STATUS_SUCCESS) {
- return '已支付的拼团订单需要等待拼团成功后才能发货';
- }
- }
- return true;
- }
-
-
-
- public function checkConfirm($value,$rule,$data)
- {
- $result = Order::where(['id'=>$value])->findOrEmpty();
-
- if ($result['shipping_status'] != 1 || $result['order_status'] != OrderEnum::ORDER_STATUS_GOODS) {
- return '此订单不允许确认收货';
- }
- return true;
- }
-
-
-
- public function checkLogistics($value,$rule,$data)
- {
- $order = Order::where(['id'=>$value])->findOrEmpty();
- $delivery = Delivery::where('order_id',$value)->findOrEmpty();
-
- if (($order['order_status'] != OrderEnum::ORDER_STATUS_GOODS && $order['order_status'] != OrderEnum::ORDER_STATUS_COMPLETE) || $delivery['send_type'] == 2) {
- return '暂无物流信息';
- }
-
- return true;
- }
- }
|