123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242 |
- <?php
- // +----------------------------------------------------------------------
- // | likeshop开源商城系统
- // +----------------------------------------------------------------------
- // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
- // | gitee下载:https://gitee.com/likeshop_gitee
- // | github下载:https://github.com/likeshop-github
- // | 访问官网:https://www.likeshop.cn
- // | 访问社区:https://home.likeshop.cn
- // | 访问手册:http://doc.likeshop.cn
- // | 微信公众号:likeshop技术社区
- // | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
- // | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
- // | 禁止对系统程序代码以任何目的,任何形式的再发布
- // | likeshop团队版权所有并拥有最终解释权
- // +----------------------------------------------------------------------
- // | author: likeshop.cn.team
- // +----------------------------------------------------------------------
-
- 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
- * @package app\shopapi\validate
- */
- 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']);
- }
-
- /**
- * @notes 检验订单是否存在
- * @param $value
- * @param $rule
- * @param $data
- * @return bool|string
- * @author ljj
- * @date 2021/11/10 3:25 下午
- */
- 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;
- }
-
- /**
- * @notes 检验订单是否可以取消
- * @param $value
- * @param $rule
- * @param $data
- * @return bool|string
- * @author ljj
- * @date 2021/11/10 4:38 下午
- */
- 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;
- }
-
- /**
- * @notes 检验订单能否删除
- * @param $value
- * @param $rule
- * @param $data
- * @return bool|string
- * @author ljj
- * @date 2021/11/10 5:21 下午
- */
- 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;
- }
-
- /**
- * @notes 检验订单能否发货
- * @param $value
- * @param $rule
- * @param $data
- * @return bool|string
- * @author ljj
- * @date 2021/11/11 10:25 上午
- */
- 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;
- }
-
- /**
- * @notes 检验订单能否确认收货
- * @param $value
- * @param $rule
- * @param $data
- * @return bool|string
- * @author ljj
- * @date 2021/11/11 11:22 上午
- */
- 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;
- }
-
- /**
- * @notes 检验订单是否有物流信息
- * @param $value
- * @param $rule
- * @param $data
- * @return bool|string
- * @author ljj
- * @date 2021/11/11 11:34 上午
- */
- 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;
- }
- }
|