截流自动化的商城平台
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

OrderValidate.php 7.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeshop开源商城系统
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | gitee下载:https://gitee.com/likeshop_gitee
  7. // | github下载:https://github.com/likeshop-github
  8. // | 访问官网:https://www.likeshop.cn
  9. // | 访问社区:https://home.likeshop.cn
  10. // | 访问手册:http://doc.likeshop.cn
  11. // | 微信公众号:likeshop技术社区
  12. // | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
  13. // | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
  14. // | 禁止对系统程序代码以任何目的,任何形式的再发布
  15. // | likeshop团队版权所有并拥有最终解释权
  16. // +----------------------------------------------------------------------
  17. // | author: likeshop.cn.team
  18. // +----------------------------------------------------------------------
  19. namespace app\shopapi\validate;
  20. use app\common\basics\Validate;
  21. use app\common\enum\OrderEnum;
  22. use app\common\model\Delivery;
  23. use app\common\model\order\Order;
  24. use app\common\model\team\Team;
  25. use app\common\model\team\TeamJoin;
  26. use think\facade\Db;
  27. /**
  28. * 商家移动端订单管理验证器
  29. * Class OrderValidate
  30. * @package app\shopapi\validate
  31. */
  32. class OrderValidate extends Validate
  33. {
  34. protected $rule = [
  35. 'id' => 'require|checkId',
  36. 'consignee' => 'require',
  37. 'province' => 'require',
  38. 'city' => 'require',
  39. 'district' => 'require',
  40. 'address' => 'require',
  41. 'mobile' => [ 'require', 'checkMobile' => [ 'check' => [ 'land', 'hk' ] ] ],
  42. 'send_type' => 'require|in:1,2',
  43. 'shipping_id' => 'requireIf:send_type,1',
  44. 'invoice_no' => 'requireIf:send_type,1',
  45. ];
  46. protected $message = [
  47. 'id.require' => '参数缺失',
  48. 'consignee.require' => '请填写收件人',
  49. 'province.require' => '地址参数缺失',
  50. 'city.require' => '地址参数缺失',
  51. 'district.require' => '地址参数缺失',
  52. 'address.require' => '请填写详细',
  53. 'mobile.require' => '请填写手机号码',
  54. 'mobile.mobile' => '请填写正确的手机号码',
  55. 'send_type.require' => '请选择快递方式',
  56. 'send_type.in' => '快递方式参数错误',
  57. 'shipping_id.requireIf' => '请选择快递公司',
  58. 'invoice_no.requireIf' => '请填写快递单号',
  59. ];
  60. public function sceneDetail()
  61. {
  62. return $this->only(['id']);
  63. }
  64. public function sceneCancel()
  65. {
  66. return $this->only(['id'])
  67. ->append('id','checkCancel');
  68. }
  69. public function sceneDel()
  70. {
  71. return $this->only(['id'])
  72. ->append('id','checkDel');
  73. }
  74. public function sceneEditAddress()
  75. {
  76. return $this->only(['id','consignee','province','city','district','address','mobile']);
  77. }
  78. public function sceneDelivery()
  79. {
  80. return $this->only(['id','send_type','shipping_id','invoice_no'])
  81. ->append('id','checkDelivery');
  82. }
  83. public function sceneConfirm()
  84. {
  85. return $this->only(['id'])
  86. ->append('id','checkConfirm');
  87. }
  88. public function sceneLogistics()
  89. {
  90. return $this->only(['id'])
  91. ->append('id','checkLogistics');
  92. }
  93. public function sceneGetAddress()
  94. {
  95. return $this->only(['id']);
  96. }
  97. /**
  98. * @notes 检验订单是否存在
  99. * @param $value
  100. * @param $rule
  101. * @param $data
  102. * @return bool|string
  103. * @author ljj
  104. * @date 2021/11/10 3:25 下午
  105. */
  106. public function checkId($value,$rule,$data)
  107. {
  108. $result = Order::where(['id'=>$value,'shop_id'=>$data['shop_id'],'del'=>0,'delete'=>0])->findOrEmpty();
  109. if ($result->isEmpty()) {
  110. return '订单不存在';
  111. }
  112. return true;
  113. }
  114. /**
  115. * @notes 检验订单是否可以取消
  116. * @param $value
  117. * @param $rule
  118. * @param $data
  119. * @return bool|string
  120. * @author ljj
  121. * @date 2021/11/10 4:38 下午
  122. */
  123. public function checkCancel($value,$rule,$data)
  124. {
  125. $result = Order::where(['id'=>$value,'shop_id'=>$data['shop_id']])->findOrEmpty();
  126. if ($result['order_status'] > OrderEnum::ORDER_STATUS_DELIVERY && $result['delivery_type'] != 2) {
  127. return '此订单不可取消';
  128. }
  129. if ($result['order_status'] > OrderEnum::ORDER_STATUS_GOODS && $result['delivery_type'] == 2) {
  130. return '此订单不可取消';
  131. }
  132. if ($result['order_type'] == OrderEnum::TEAM_ORDER) {
  133. $found = Db::name('team_join')->where(['order_id' => $order['id']])->find();
  134. if ($found['status'] == Team::STATUS_WAIT_SUCCESS) {
  135. return '已支付的拼团订单需要有拼团结果才可以取消';
  136. }
  137. }
  138. return true;
  139. }
  140. /**
  141. * @notes 检验订单能否删除
  142. * @param $value
  143. * @param $rule
  144. * @param $data
  145. * @return bool|string
  146. * @author ljj
  147. * @date 2021/11/10 5:21 下午
  148. */
  149. public function checkDel($value,$rule,$data)
  150. {
  151. $result = Order::where(['id'=>$value,'shop_id'=>$data['shop_id']])->findOrEmpty();
  152. if ($result['order_status'] != OrderEnum::ORDER_STATUS_DOWN) {
  153. return '此订单不可删除';
  154. }
  155. return true;
  156. }
  157. /**
  158. * @notes 检验订单能否发货
  159. * @param $value
  160. * @param $rule
  161. * @param $data
  162. * @return bool|string
  163. * @author ljj
  164. * @date 2021/11/11 10:25 上午
  165. */
  166. public function checkDelivery($value,$rule,$data)
  167. {
  168. $result = Order::where(['id'=>$value])->findOrEmpty();
  169. if ($result['shipping_status'] == 1) {
  170. return '订单已发货';
  171. }
  172. if ($result['order_type'] == OrderEnum::TEAM_ORDER) {
  173. $join = TeamJoin::where(['order_id' => $result['id']])->findOrEmpty();
  174. if ($join['status'] != Team::STATUS_SUCCESS) {
  175. return '已支付的拼团订单需要等待拼团成功后才能发货';
  176. }
  177. }
  178. return true;
  179. }
  180. /**
  181. * @notes 检验订单能否确认收货
  182. * @param $value
  183. * @param $rule
  184. * @param $data
  185. * @return bool|string
  186. * @author ljj
  187. * @date 2021/11/11 11:22 上午
  188. */
  189. public function checkConfirm($value,$rule,$data)
  190. {
  191. $result = Order::where(['id'=>$value])->findOrEmpty();
  192. if ($result['shipping_status'] != 1 || $result['order_status'] != OrderEnum::ORDER_STATUS_GOODS) {
  193. return '此订单不允许确认收货';
  194. }
  195. return true;
  196. }
  197. /**
  198. * @notes 检验订单是否有物流信息
  199. * @param $value
  200. * @param $rule
  201. * @param $data
  202. * @return bool|string
  203. * @author ljj
  204. * @date 2021/11/11 11:34 上午
  205. */
  206. public function checkLogistics($value,$rule,$data)
  207. {
  208. $order = Order::where(['id'=>$value])->findOrEmpty();
  209. $delivery = Delivery::where('order_id',$value)->findOrEmpty();
  210. if (($order['order_status'] != OrderEnum::ORDER_STATUS_GOODS && $order['order_status'] != OrderEnum::ORDER_STATUS_COMPLETE) || $delivery['send_type'] == 2) {
  211. return '暂无物流信息';
  212. }
  213. return true;
  214. }
  215. }