VerificationLogic.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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\logic;
  20. use app\common\enum\AfterSaleEnum;
  21. use app\common\enum\OrderEnum;
  22. use app\common\enum\OrderLogEnum;
  23. use app\common\enum\VerificationEnum;
  24. use app\common\enum\YesNoEnum;
  25. use app\common\logic\BaseLogic;
  26. use app\common\model\AfterSale;
  27. use app\common\model\Order;
  28. use app\common\model\OrderGoods;
  29. use app\common\model\OrderLog;
  30. use app\common\model\SelffetchVerifier;
  31. use app\common\model\Verification;
  32. use app\common\service\ConfigService;
  33. class VerificationLogic extends BaseLogic
  34. {
  35. /**
  36. * @notes 提货核销
  37. * @param $params
  38. * @return array
  39. * @throws \think\db\exception\DataNotFoundException
  40. * @throws \think\db\exception\DbException
  41. * @throws \think\db\exception\ModelNotFoundException
  42. * @author ljj
  43. * @date 2021/8/27 5:38 下午
  44. */
  45. public static function verification($params)
  46. {
  47. $result = Order::where('pickup_code',$params['pickup_code'])
  48. ->with(['order_goods' => function ($query) {
  49. $query->field('id,order_id,goods_snap,goods_name,goods_num')
  50. ->append(['goods_image', 'spec_value_str'])
  51. ->hidden(['goods_snap']);
  52. }])
  53. ->append(['verification_status_desc'])
  54. ->field('id,address,verification_status')
  55. ->find()
  56. ->toArray();
  57. //校验是否有售后
  58. foreach ($result['order_goods'] as &$goods) {
  59. $goods['after_sale'] = AfterSale::where('order_goods_id', $goods['id'])
  60. ->field([ 'id', 'order_goods_id', 'status' ])
  61. ->order('id desc')
  62. ->findOrEmpty();
  63. }
  64. $result['contact'] = $result['address']->contact;
  65. unset($result['address']);
  66. return $result;
  67. }
  68. /**
  69. * @notes 确认提货
  70. * @param $params
  71. * @return bool
  72. * @author ljj
  73. * @date 2021/8/27 6:05 下午
  74. */
  75. public static function verificationConfirm($params)
  76. {
  77. try {
  78. $order = Order::find($params['id']);
  79. $selffetch_verifier = SelffetchVerifier::where(['user_id'=>$params['user_id'],'selffetch_shop_id'=>$order['selffetch_shop_id'],'status'=>1])->find();
  80. //添加核销记录
  81. $snapshot = [
  82. 'sn' => $selffetch_verifier['sn'],
  83. 'name' => $selffetch_verifier['name']
  84. ];
  85. $verification = new Verification;
  86. $verification->order_id = $order['id'];
  87. $verification->selffetch_shop_id = $order['selffetch_shop_id'];
  88. $verification->handle_id = $params['user_id'];
  89. $verification->verification_scene = VerificationEnum::TYPE_USER;
  90. $verification->snapshot = json_encode($snapshot);
  91. $verification->save();
  92. //更新订单状态
  93. $order->order_status = OrderEnum::STATUS_FINISH;
  94. $order->verification_status = OrderEnum::WRITTEN_OFF;
  95. $order->confirm_take_time = time();
  96. $order->after_sale_deadline = self::getAfterSaleDeadline();
  97. $order->save();
  98. //订单日志
  99. (new OrderLog())->record([
  100. 'type' => OrderLogEnum::TYPE_USER,
  101. 'channel' => OrderLogEnum::USER_VERIFICATION,
  102. 'order_id' => $order['id'],
  103. 'operator_id' => $params['user_id'],
  104. ]);
  105. return true;
  106. } catch (\Exception $e) {
  107. //错误
  108. self::$error = $e->getMessage();
  109. return false;
  110. }
  111. }
  112. /**
  113. * @notes 获取当前售后
  114. * @return float|int
  115. * @author ljj
  116. * @date 2021/9/1 3:09 下午
  117. */
  118. public static function getAfterSaleDeadline()
  119. {
  120. //是否关闭维权
  121. $afterSale = ConfigService::get('transaction', 'after_sales');
  122. //可维权时间
  123. $afterSaleDays = ConfigService::get('transaction', 'after_sales_days');
  124. if ($afterSale == YesNoEnum::NO) {
  125. $afterSaleDeadline = time();
  126. } else {
  127. $afterSaleDeadline = ($afterSaleDays * 24 * 60 * 60) + time();
  128. }
  129. return $afterSaleDeadline;
  130. }
  131. }