ConsumptionScore.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace app\command;
  3. use app\common\repositories\merchant\MerchantRepository;
  4. use think\console\Command;
  5. use think\console\Input;
  6. use think\console\Output;
  7. use think\facade\Db;
  8. use think\facade\Log;
  9. class ConsumptionScore extends Command
  10. {
  11. protected function configure()
  12. {
  13. // 指令配置
  14. $this->setName('ConsumptionScore')
  15. ->setDescription('ConsumptionScore');
  16. }
  17. protected function execute(Input $input, Output $output)
  18. {
  19. Log::info('ConsumptionScore:start');
  20. Db::startTrans();
  21. try {
  22. $this -> a();
  23. $this -> b();
  24. // 提交事务
  25. Db::commit();
  26. } catch (\Exception $e) {
  27. // 回滚事务
  28. Db::rollback();
  29. Log::info('ConsumptionScore:error'.$e->getFile().':'.$e->getLine().'【'.$e->getMessage().'】');
  30. $output->writeln('执行失败'.$e->getFile().':'.$e->getLine().'【'.$e->getMessage().'】');
  31. }
  32. Log::info('ConsumptionScore:end');
  33. $output->writeln('执行成功');
  34. }
  35. public function a(){
  36. //所有开启了消费分的商户
  37. $MerchantRepository = app()->make( MerchantRepository::class);
  38. $merList = $MerchantRepository -> getConsumptionScoreMer();
  39. // if($merList){
  40. // $merList = $merList -> toArray();
  41. // }
  42. Log::info($merList);
  43. foreach ($merList as $key => $value){
  44. $mer_money = $MerchantRepository -> getConsumptionScoreLog($value['mer_id']);
  45. if($mer_money >= 1){
  46. $MerchantRepository -> consumptionScore($value['mer_id'],$value['uid'],$mer_money,$mer_money,100);
  47. }
  48. }
  49. }
  50. public function b(){
  51. //需要释放的积分
  52. $MerchantRepository = app()->make( MerchantRepository::class);
  53. $scoreList = $MerchantRepository -> consumptionScoreList();
  54. foreach ($scoreList as $key => $value) {
  55. $MerchantRepository -> consumptionScore($value['mer_id'],$value['uid'],'','','',$value['id']);
  56. }
  57. }
  58. }