12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <?php
- // +----------------------------------------------------------------------
- // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
- // +----------------------------------------------------------------------
- // | Author: 萤火科技 <admin@yiovo.com>
- // +----------------------------------------------------------------------
- declare (strict_types=1);
- namespace app\console\service;
- use app\common\service\commission\GiveOutCommission;
- use app\common\service\BaseService;
- use app\common\service\Message;
- use app\console\library\Tools;
- use app\common\model\user\CommissionsDetail as CommissionDetailModel;
- /**
- * 服务类:结算分佣模块
- * Class Commissions
- * @package app\console\service
- */
- class Commissions extends BaseService
- {
- public function finishClearing($storeId){
- // 获取所有可用有效的分佣记录
- $list = $this->getUsableList($storeId);
- log_record('info::'.json_encode($list),'info');
- // 遍历待分佣记录,逐个结算佣金
- $data = [];
- $infos = [];
- $e = env('APP_DEBUG');
- if (!$list->isEmpty()){
- foreach ($list as $key=>$detail) {
- if (GiveOutCommission::endCommissionDetail($detail,$data) === false){
- $infos[] = '分佣失败commissionId::'.$detail->id;
- }
- }
- }
- //将order_goods的标记为已结算
- if (count($data)){
- \app\console\model\Order::whereIn('order_id',$data)->update(['commission_settlement_status'=>1]);
- }
- Tools::taskLogs('Commissions', 'finishClearing', [
- 'storeId' => $storeId,
- 'OrderIds' => $data
- ]);
- if(count($infos)){
- log_record('finishClearing error ::'.json_encode($infos),'error');
- }
- /* if ($e == true && count($infos)){
- $dataStr = implode(',',$infos);
- Message::wxRobot('OrderIds::'.$dataStr);
- }*/
- if ($e == true && count($data)){
- Message::wxRobot('OK OrderIds::'.json_encode($data));
- }
- }
- /**
- * 获取所有会员等级
- * @param int $storeId 商城ID
- * @return false|\think\Collection
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- private function getUsableList(int $storeId)
- {
- return CommissionDetailModel::getUsableList($storeId);
- }
- }
|