setName('ConsumptionScore') ->setDescription('ConsumptionScore'); } protected function execute(Input $input, Output $output) { Log::info('ConsumptionScore:start'); Db::startTrans(); try { $this -> a(); $this -> b(); // 提交事务 Db::commit(); } catch (\Exception $e) { // 回滚事务 Db::rollback(); Log::info('ConsumptionScore:error'.$e->getFile().':'.$e->getLine().'【'.$e->getMessage().'】'); $output->writeln('执行失败'.$e->getFile().':'.$e->getLine().'【'.$e->getMessage().'】'); } Log::info('ConsumptionScore:end'); $output->writeln('执行成功'); } public function a(){ //所有开启了消费分的商户 $MerchantRepository = app()->make( MerchantRepository::class); $merList = $MerchantRepository -> getConsumptionScoreMer(); // if($merList){ // $merList = $merList -> toArray(); // } Log::info($merList); foreach ($merList as $key => $value){ $mer_money = $MerchantRepository -> getConsumptionScoreLog($value['mer_id']); if($mer_money >= 1){ $MerchantRepository -> consumptionScore($value['mer_id'],$value['uid'],$mer_money,$mer_money,100); } } } public function b(){ //需要释放的积分 $MerchantRepository = app()->make( MerchantRepository::class); $scoreList = $MerchantRepository -> consumptionScoreList(); foreach ($scoreList as $key => $value) { $MerchantRepository -> consumptionScore($value['mer_id'],$value['uid'],'','','',$value['id']); } } }