RefundCompensate.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types=1);
  12. namespace app\api\model;
  13. use app\api\model\Setting as SettingModel;
  14. use app\api\service\User as UserService;
  15. use app\api\model\OrderGoods as OrderGoodsModel;
  16. // use app\common\model\order\RefundHis as RefundHisModel;
  17. // use app\common\model\order\RefundHis;
  18. use app\common\model\RefundCompensate as RefundCompensateModel;
  19. // use app\common\enum\order\refund\RefundType as RefundTypeEnum;
  20. // use app\common\enum\order\refund\AuditStatus as AuditStatusEnum;
  21. // use app\common\enum\order\refund\RefundStatus as RefundStatusEnum;
  22. // use app\common\enum\order\refund\FinanceRefundStatus as FinanceRefundStatusEnum;
  23. use app\common\exception\BaseException;
  24. use app\common\service\Kuaidi as KuaidiService;
  25. // use app\store\model\OrderGoods;
  26. /**
  27. * 售后补偿单模型
  28. * Class OrderRefund
  29. * @package app\api\model
  30. */
  31. class RefundCompensate extends RefundCompensateModel
  32. {
  33. /**
  34. * 隐藏字段
  35. * @var array
  36. */
  37. protected $hidden = [
  38. // 'store_id',
  39. // 'update_time'
  40. ];
  41. /**
  42. * 追加字段
  43. * @var array
  44. */
  45. protected $append = [
  46. // 'state_text', // 售后单状态
  47. // 'dfh_time', // 待用户发货倒计时
  48. ];
  49. // /**
  50. // * 售后单状态文字描述
  51. // * @param $value
  52. // * @param $data
  53. // * @return string
  54. // */
  55. // public function getStateTextAttr($value, $data)
  56. // {
  57. // if($data['delivery_type']==10){
  58. // // 已完成
  59. // if ($data['status'] == RefundStatusEnum::COMPLETED) {
  60. // return ['value'=>1,'name'=>'退款成功'];
  61. // }
  62. // // 已取消
  63. // if ($data['status'] == RefundStatusEnum::CANCELLED) {
  64. // return ['value'=>2,'name'=>'已取消'];
  65. // }
  66. // // 已拒绝
  67. // if ($data['status'] == RefundStatusEnum::REJECTED) {
  68. // return ['value'=>3,'name'=>'平台已拒绝'];
  69. // }
  70. // //已关闭 -用户超时未退货,系统自动关闭售后单
  71. // if ($data['status'] == RefundStatusEnum::CLOSE) {
  72. // return ['value'=>7,'name'=>'已关闭'];
  73. // }
  74. // // 进行中
  75. // if ($data['status'] == RefundStatusEnum::NORMAL) {
  76. // //退货退款
  77. // if ($data['type'] == RefundTypeEnum::RETURN) {
  78. // if (isset($data['audit_status_zg'])&&$data['audit_status_zg'] == AuditStatusEnum::WAIT) {
  79. // return ['value'=>0,'name'=>'待审核'];
  80. // }
  81. // if(isset($data['is_user_send'])&&$data['is_user_send']){ //已发货
  82. // if($data['is_receipt']){//已收货
  83. // return ['value'=>6,'name'=>'待退款'];
  84. // }
  85. // return ['value'=>5,'name'=>'待仓库收货'];
  86. // }else{
  87. // return ['value'=>4,'name'=>'待买家退货'];
  88. // }
  89. // }else{
  90. // if (isset($data['audit_status'])&&$data['audit_status'] == AuditStatusEnum::WAIT) { //仅退款不需要主管审核
  91. // return ['value'=>0,'name'=>'待审核'];
  92. // }
  93. // if($data['finance_refund'] == FinanceRefundStatusEnum::WAIT){
  94. // return ['value'=>6,'name'=>'待退款'];
  95. // }
  96. // }
  97. // }
  98. // }
  99. // if($data['delivery_type']==20){
  100. // if ($data['status'] == RefundStatusEnum::COMPLETED) {
  101. // return ['value'=>1,'name'=>'退款成功'];
  102. // }
  103. // //已关闭 -用户超时未退货,系统自动关闭售后单
  104. // if ($data['status'] == RefundStatusEnum::CLOSE) {
  105. // return ['value'=>7,'name'=>'已关闭'];
  106. // }
  107. // if ($data['status'] == RefundStatusEnum::NORMAL) {
  108. // if (isset($data['audit_status'])&&$data['audit_status'] == AuditStatusEnum::WAIT) {
  109. // return ['value'=>0,'name'=>'待审核'];
  110. // }
  111. // if ($data['audit_status'] == AuditStatusEnum::REVIEWED&&$data['finance_refund']==0) {
  112. // return ['value'=>6,'name'=>'待退款'];
  113. // }
  114. // }
  115. // }
  116. // return $value;
  117. // }
  118. /**
  119. * 待用户发货倒计时时间戳
  120. * @param $value
  121. * @param $data
  122. * @return int
  123. * @author: zjwhust
  124. * @Time: 2021/10/8 17:06
  125. */
  126. // public function getDfhTimeAttr($value,$data){
  127. // if (
  128. // $data['type'] == RefundTypeEnum::RETURN
  129. // && $data['audit_status'] == AuditStatusEnum::REVIEWED
  130. // && $data['audit_status_zg'] == AuditStatusEnum::REVIEWED
  131. // && $data['is_user_send'] == 0
  132. // && $data['status'] == RefundStatusEnum::NORMAL
  133. // ) {
  134. // $now = time();
  135. // $delay_time = 86400 * 7;//获取待发货时间
  136. // if(env('SERVE_ENV')=='test'){
  137. // $delay_time = 300;//测试超时退款5分钟
  138. // }
  139. // if(($now-$data['approved_time'])<$delay_time){ //
  140. // return $data['approved_time']+$delay_time-$now;
  141. // }
  142. // }
  143. // return 0;
  144. // }
  145. /**
  146. * 获取用户售后单列表
  147. * @param int $state 售后单状态 -1为全部
  148. * @return \think\Paginator
  149. * @throws \app\common\exception\BaseException
  150. * @throws \think\db\exception\DbException
  151. */
  152. // public function getList(int $state = -1)
  153. // {
  154. // // 检索查询条件
  155. // $filter = [];
  156. // // 售后单状态
  157. // $state > -1 && $filter[] = ['status', '=', $state];
  158. // // 当前用户ID
  159. // $userId = UserService::getCurrentLoginUserId();
  160. // // 查询列表记录
  161. // return $this->with(['orderGoods.image', 'orderGoodsAll.image'])
  162. // ->where($filter)
  163. // ->where('user_id', '=', $userId)
  164. // ->order(['create_time' => 'desc'])
  165. // ->paginate(15)
  166. // ->each(function($item) {
  167. // if (!$item['order_goods_id']) {
  168. // // 整单退款
  169. // $orderGoods = $item['orderGoodsAll'];
  170. // } else {
  171. // $orderGoods = [$item['orderGoods']];
  172. // }
  173. // unset($item['orderGoods'], $item['orderGoodsAll']);
  174. // $item['orderGoods'] = $orderGoods;
  175. // });
  176. // }
  177. // /**
  178. // * 获取数量
  179. // * @return int
  180. // * @throws BaseException
  181. // */
  182. // public function getCount()
  183. // {
  184. // // 当前用户ID
  185. // $userId = UserService::getCurrentLoginUserId();
  186. // return $this->where('user_id', '=', $userId)
  187. // ->where('status', '=', 0)
  188. // ->count();
  189. // }
  190. // /**
  191. // * 获取当前用户的售后单详情
  192. // * @param int $orderRefundId 售后单ID
  193. // * @param bool $isWith 是否关联
  194. // * @return static|null
  195. // * @throws BaseException
  196. // */
  197. // public static function getDetail(int $orderRefundId, $isWith = false)
  198. // {
  199. // // 关联查询
  200. // $with = $isWith ? ['orderGoods' => ['image'], 'orderGoodsAll' => ['image'], 'address','shops'] : [];
  201. // // 获取记录
  202. // $detail = static::detail([
  203. // 'user_id' => UserService::getCurrentLoginUserId(),
  204. // 'order_refund_id' => $orderRefundId
  205. // ], $with);
  206. // // $detail = static::where("order_refund_id",$orderRefundId)->find();
  207. // if (empty($detail)) throwError('未找到该售后单');
  208. // if (!$detail['order_goods_id']) {
  209. // // 整单退款
  210. // $orderGoods = $detail['orderGoodsAll'];
  211. // } else {
  212. // $orderGoods = [$detail['orderGoods']];
  213. // }
  214. // unset($detail['orderGoods'], $detail['orderGoodsAll']);
  215. // $detail['orderGoods'] = $orderGoods;
  216. // return $detail;
  217. // }
  218. // /**
  219. // * 订单商品详情
  220. // * @param int $orderGoodsId 订单商品ID
  221. // * @return \app\common\model\OrderGoods|null
  222. // * @throws BaseException
  223. // */
  224. // public function getRefundGoods(int $orderGoodsId)
  225. // {
  226. // $goods = OrderGoodsModel::detail($orderGoodsId);
  227. // if (isset($goods['refund']) && !empty($goods['refund'])) {
  228. // throwError('当前商品已申请售后');
  229. // }
  230. // return $goods;
  231. // }
  232. // /**
  233. // * 用户撤销申请
  234. // * @param $data
  235. // * @return false|int
  236. // */
  237. // public function revoke()
  238. // {
  239. // $user = UserService::getCurrentLoginUser(true);
  240. // $type = false;
  241. // if($this['status'] == RefundStatusEnum::REJECTED){//已拒绝
  242. // $type = true;
  243. // }else{
  244. // if($this['status'] == RefundStatusEnum::NORMAL){//进行中&待审核
  245. // if($this['delivery_type']==10){
  246. // if ($this['type'] == RefundTypeEnum::RETURN) {
  247. // if ($this['audit_status_zg'] == AuditStatusEnum::WAIT) {
  248. // $type = true;
  249. // }
  250. // }else{
  251. // if ($this['audit_status'] == AuditStatusEnum::WAIT) { //仅退款不需要主管审核
  252. // $type = true;
  253. // }
  254. // }
  255. // }
  256. // //自提单 当门店未审核时可以撤回
  257. // if($this['delivery_type']==20){
  258. // if ($this['audit_status'] == AuditStatusEnum::WAIT) { //仅退款不需要主管审核
  259. // $type = true;
  260. // }
  261. // }
  262. // }
  263. // }
  264. // if($type){
  265. // return $this->transaction(function () use ($user) {
  266. // if($this['delivery_type']==10){
  267. // $this->save([
  268. // 'status' => RefundStatusEnum::CANCELLED,
  269. // ]);
  270. // }
  271. // //门店自提单自动关闭
  272. // if($this['delivery_type']==20){
  273. // $this->save([
  274. // 'status' => RefundStatusEnum::CLOSE,
  275. // ]);
  276. // }
  277. // //订单商品解冻
  278. // OrderGoodsModel::updateBase(['frozen_status' => 0], ['order_goods_id'=>$this['order_goods_id']]);
  279. // $json_str = json_encode(["买家已撤销申请,退款已关闭"]);
  280. // (new RefundHisModel())->add($this['order_refund_id'],$user['nick_name'],4,$json_str,'','买家','撤销申请');
  281. // return true;
  282. // });
  283. // }
  284. // $this->error = '当前售后单不合法,不允许该操作';
  285. // return false;
  286. // }
  287. // /**
  288. // * 用户发货
  289. // * @param $data
  290. // * @return false|int
  291. // */
  292. // public function delivery(array $data)
  293. // {
  294. // if (
  295. // $this['type'] != RefundTypeEnum::RETURN
  296. // || $this['audit_status_zg'] != AuditStatusEnum::REVIEWED
  297. // || $this['is_user_send'] != 0
  298. // ) {
  299. // $this->error = '当前售后单不合法,不允许该操作';
  300. // return false;
  301. // }
  302. // if ($data['expressId'] <= 0) {
  303. // $this->error = '请选择物流公司';
  304. // return false;
  305. // }
  306. // if (empty($data['expressNo'])) {
  307. // $this->error = '请填写物流单号';
  308. // return false;
  309. // }
  310. // if (empty($data['expressCompany'])) {
  311. // $this->error = '请填写物流公司名称';
  312. // return false;
  313. // }
  314. // if (isset($data['expressDesc']) && mb_strlen($data['expressDesc'])>50) {
  315. // $this->error = '退货字数上限超过了50字';
  316. // return false;
  317. // }
  318. // // 请求快递100订阅接口
  319. // $subscribe = KuaidiService::subscribe($data['expressNo'], 2);
  320. // if(!$subscribe->result){
  321. // if(stripos($subscribe->message,"重复订阅") === false){ //重复订阅允许提交物流
  322. // $this->error = '物流单号订阅异常:'.$subscribe->message;
  323. // return false;
  324. // }
  325. // }
  326. // $user = UserService::getCurrentLoginUser(true);
  327. // return $this->transaction(function () use ($data,$user) {
  328. // $this->save([
  329. // 'is_user_send' => 1,
  330. // 'send_time' => time(),
  331. // 'express_id' => (int)$data['expressId'],
  332. // 'express_no' => $data['expressNo'],
  333. // 'express_company' => $data['expressCompany'],
  334. // 'express_desc' => $data['expressDesc']??'',
  335. // ]);
  336. // $json_str = json_encode(["买家寄回商品","快递公司:".$data['expressCompany'],"物流单号:".$data['expressNo']]);
  337. // (new RefundHisModel())->add($this['order_refund_id'],$user['nick_name'],7,$json_str,'','买家','买家填写物流单号');
  338. // return true;
  339. // });
  340. // }
  341. // /**
  342. // * 门店审核售后单
  343. // * @param $data
  344. // * @return false|int
  345. // */
  346. // public function auditStatus($param,$user){
  347. // // 验证订单是否合法
  348. // // 条件1: 门店审核状态不在审核中
  349. // // 条件2: 售后单状态不在进行中
  350. // if ($this['audit_status'] != 0 || $this['status'] != 0) {
  351. // $this->error = '该售后单已经处理';
  352. // return false;
  353. // }
  354. // return $this->transaction(function () use ($param,$user) {
  355. // // 更新售后单状态
  356. // $status = $this->save([
  357. // 'audit_status' => $param['audit_status'],
  358. // 'refuse_desc' => $param['audit_status']==20 ? $param['refuse_desc'] : '',
  359. // 'refuse_images' => $param['audit_status']==20 ? $param['refuse_images']??'' : '',
  360. // 'status' => $param['audit_status']==20 ? 40 : 0,
  361. // 'hx_refund_time' => time(),
  362. // 'hx_refund_user_id' => UserService::getCurrentLoginUserId(),
  363. // 'is_user_send' => 1,
  364. // 'is_receipt' => 1,
  365. // ]);
  366. // if($this['order_goods_id']>0) {
  367. // OrderGoodsModel::where('order_goods_id', $this['order_goods_id'])->update(['frozen_status' => 0]);
  368. // }
  369. // if($param['audit_status']==20){
  370. // $json_str = json_encode(["处理结果:拒绝","拒绝理由:".$param['refuse_desc'],"门店拒绝退货,退款单关闭"]);
  371. // $his_type = 13;
  372. // $name = $this['shops']['shop_name'];
  373. // $pf_operator = $user['nick_name']."(".$user['mobile'].")";
  374. // (new RefundHis())->add($this['order_refund_id'],$name,$his_type,$json_str,$param['refuse_images'],$pf_operator,'拒绝并关闭退货单');
  375. // }else{
  376. // $json_str = json_encode(["处理结果:同意","门店同意退货,等待财务退款"]);
  377. // $his_type = 12;
  378. // $name = $this['shops']['shop_name'];
  379. // $pf_operator = $user['nick_name']."(".$user['mobile'].")";
  380. // (new RefundHis())->add($this['order_refund_id'],$name,$his_type,$json_str,'',$pf_operator,'同意退货并确认收货');
  381. // }
  382. // return $status;
  383. // });
  384. // }
  385. // /**
  386. // * 新增售后单记录
  387. // * @param int $orderGoodsId 订单商品ID
  388. // * @param array $data 用户提交的表单数据
  389. // * @return mixed
  390. // * @throws BaseException
  391. // */
  392. // public function apply(int $orderGoodsId, array $data)
  393. // {
  394. // // 订单商品详情
  395. // $goods = $this->getRefundGoods($orderGoodsId);
  396. // return $this->transaction(function () use ($orderGoodsId, $data, $goods) {
  397. // // 新增售后单记录
  398. // $this->save([
  399. // 'order_goods_id' => $orderGoodsId,
  400. // 'order_id' => $goods['order_id'],
  401. // 'user_id' => UserService::getCurrentLoginUserId(),
  402. // 'type' => $data['type'],
  403. // 'apply_desc' => $data['content'],
  404. // 'audit_status' => AuditStatusEnum::WAIT,
  405. // 'status' => 0,
  406. // 'store_id' => self::$storeId
  407. // ]);
  408. // // 记录凭证图片关系
  409. // if (isset($data['images']) && !empty($data['images'])) {
  410. // $this->saveImages((int)$this['order_refund_id'], $data['images']);
  411. // }
  412. // return true;
  413. // });
  414. // }
  415. // /**
  416. // * 记录售后单图片
  417. // * @param int $orderRefundId 售后单ID
  418. // * @param array $images 图片列表
  419. // * @return bool
  420. // */
  421. // private function saveImages(int $orderRefundId, array $images)
  422. // {
  423. // // 生成评价图片数据
  424. // $data = [];
  425. // foreach ($images as $imageId) {
  426. // $data[] = [
  427. // 'order_refund_id' => $orderRefundId,
  428. // 'image_id' => $imageId,
  429. // 'store_id' => self::$storeId
  430. // ];
  431. // }
  432. // return !empty($data) && (new OrderRefundImage)->addAll($data) !== false;
  433. // }
  434. }