Commissions.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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\console\service;
  13. use app\common\service\commission\GiveOutCommission;
  14. use app\common\service\BaseService;
  15. use app\common\service\Message;
  16. use app\console\library\Tools;
  17. use app\common\model\user\CommissionsDetail as CommissionDetailModel;
  18. /**
  19. * 服务类:结算分佣模块
  20. * Class Commissions
  21. * @package app\console\service
  22. */
  23. class Commissions extends BaseService
  24. {
  25. public function finishClearing($storeId){
  26. // 获取所有可用有效的分佣记录
  27. $list = $this->getUsableList($storeId);
  28. log_record('info::'.json_encode($list),'info');
  29. // 遍历待分佣记录,逐个结算佣金
  30. $data = [];
  31. $infos = [];
  32. $e = env('APP_DEBUG');
  33. if (!$list->isEmpty()){
  34. foreach ($list as $key=>$detail) {
  35. if (GiveOutCommission::endCommissionDetail($detail,$data) === false){
  36. $infos[] = '分佣失败commissionId::'.$detail->id;
  37. }
  38. }
  39. }
  40. //将order_goods的标记为已结算
  41. if (count($data)){
  42. \app\console\model\Order::whereIn('order_id',$data)->update(['commission_settlement_status'=>1]);
  43. }
  44. Tools::taskLogs('Commissions', 'finishClearing', [
  45. 'storeId' => $storeId,
  46. 'OrderIds' => $data
  47. ]);
  48. if(count($infos)){
  49. log_record('finishClearing error ::'.json_encode($infos),'error');
  50. }
  51. /* if ($e == true && count($infos)){
  52. $dataStr = implode(',',$infos);
  53. Message::wxRobot('OrderIds::'.$dataStr);
  54. }*/
  55. if ($e == true && count($data)){
  56. Message::wxRobot('OK OrderIds::'.json_encode($data));
  57. }
  58. }
  59. /**
  60. * 获取所有会员等级
  61. * @param int $storeId 商城ID
  62. * @return false|\think\Collection
  63. * @throws \think\db\exception\DataNotFoundException
  64. * @throws \think\db\exception\DbException
  65. * @throws \think\db\exception\ModelNotFoundException
  66. */
  67. private function getUsableList(int $storeId)
  68. {
  69. return CommissionDetailModel::getUsableList($storeId);
  70. }
  71. }