| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- <?php
- namespace app\command;
- use app\common\repositories\merchant\MerchantRepository;
- use think\console\Command;
- use think\console\Input;
- use think\console\Output;
- use think\facade\Db;
- use think\facade\Log;
- class ConsumptionScore extends Command
- {
- protected function configure()
- {
- // 指令配置
- $this->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']);
- }
- }
- }
|