RefundBatchResend.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Name: 芸众商城系统
  5. * Author: 广州市芸众信息科技有限公司
  6. * Profile: 广州市芸众信息科技有限公司位于国际商贸中心的广州,专注于移动电子商务生态系统打造,拥有芸众社交电商系统、区块链数字资产管理系统、供应链管理系统、电子合同等产品/服务。官网 :www.yunzmall.com www.yunzshop.com
  7. * Date: 2021/12/27
  8. * Time: 19:20
  9. */
  10. namespace app\backend\modules\refund\services\operation;
  11. use app\common\models\refund\RefundGoodsLog;
  12. use app\common\models\refund\RefundProcessLog;
  13. use app\common\models\refund\ResendExpress;
  14. use app\common\repositories\ExpressCompany;
  15. class RefundBatchResend extends RefundOperation
  16. {
  17. protected $statusBeforeChange = [self::WAIT_RETURN_GOODS,self::WAIT_RECEIVE_RETURN_GOODS,self::WAIT_RESEND_GOODS];
  18. protected $statusAfterChanged = self::WAIT_RESEND_GOODS;
  19. protected $name = '商家分批发货';
  20. protected $timeField = 'send_time';
  21. protected $resendExpress;
  22. protected function updateBefore()
  23. {
  24. $expressData = $this->getRequest()->only('express_company_name', 'express_sn');
  25. $expressData['company_code'] = $this->getRequest()->input('express_company_code');
  26. $expressData['express_company_name'] = array_get(ExpressCompany::create()->where('value', $expressData['express_company_code'])->first(), 'name', '其他快递');
  27. $order_goods = $this->getRequest()->input('pack_goods');
  28. if ($order_goods) {
  29. foreach ($order_goods as $goods) {
  30. $refundGoods = $this->refundOrderGoods->where('order_goods_id', $goods['id'])->first();
  31. if ($refundGoods) {
  32. $expressData['pack_goods'][] = [
  33. 'order_goods_id' => $refundGoods->order_goods_id,
  34. 'title' => $refundGoods->goods_title,
  35. 'goods_option_title' => $refundGoods->goods_option_title,
  36. 'thumb' => $refundGoods->goods_thumb,
  37. 'total' => $goods['num'],
  38. ];
  39. $refundGoods->fill(['send_num'=> max($refundGoods->send_num - $goods['num'],0)])->save();
  40. }
  41. }
  42. }
  43. $resendExpress = new ResendExpress($expressData);
  44. $this->resendExpress()->save($resendExpress);
  45. $this->resendExpress = $resendExpress;
  46. }
  47. protected function updateAfter()
  48. {
  49. $number = RefundGoodsLog::where('refund_id', $this->id)->get()->sum('send_num');
  50. //没有商品发货完成
  51. if ($number <= 0) {
  52. $this->status = self::WAIT_RECEIVE_RESEND_GOODS;
  53. $this->save();
  54. }
  55. }
  56. protected function writeLog()
  57. {
  58. $detail = [
  59. '快递公司:'.$this->resendExpress->express_company_name,
  60. '快递单号:'.$this->resendExpress->express_sn,
  61. ];
  62. $processLog = RefundProcessLog::logInstance($this, RefundProcessLog::OPERATOR_SHOP);
  63. $processLog->setAttribute('operate_type', RefundProcessLog::OPERATE_SHOP_BATCH_RESEND);
  64. $processLog->saveLog($detail);
  65. }
  66. }