1 <?php 2 3 namespace App\Console\Commands; 4 5 use Illuminate\Console\Command; 6 use App\Libs\wxpay\CLogFileHandler; 7 use App\Libs\wxpay\Log; 8 use App\Helpers\ReportHelper; 9 use App\Helpers\CommonHelper; 10 use App\Models\Ecg_customer; 11 use App\Models\Ecg_report; 12 use App\Models\Order; 13 use App\Models\Order_good; 14 use App\Models\Goods; 15 16 class AddUserCombo extends Command 17 { 18 19 /** 20 * The name and signature of the console command. 21 * 22 * @var string 23 */ 24 25 protected $signature = ‘add_user_combo:run {--uid=} {--spe_goo_id=}‘; //传参 26 27 /** 28 * The console command description. 29 * 30 * @var string 31 */ 32 protected $description = ‘Command description‘; 33 34 /** 35 * Create a new command instance. 36 * 37 * @return void 38 */ 39 public function __construct() 40 { 41 parent::__construct(); 42 } 43 44 /** 45 * php artisan add_user_combo:run --uid=88 --spe_goo_id=9 46 * 47 * Execute the console command. 48 * 49 * @return mixed 50 */ 51 public function handle() 52 { 53 54 //$uid = 219; 55 $ord_typ_id = 1; //为e心明用户添加特殊的套餐 56 //$spe_goo_id = 8; //特殊套餐的商品id 57 58 $uid = $this->option(‘uid‘); 59 $spe_goo_id = $this->option(‘spe_goo_id‘); 60 61 $info = array( 62 ‘ord_typ_id‘=>$ord_typ_id, 63 ‘out_trade_no‘=>CommonHelper::get_order_sn(), 64 ‘use_id‘=>$uid, 65 ‘ord_sta_id‘=>1, 66 ‘ord_display‘=>0, 67 ‘ord_pay_sta_id‘=>1, 68 ‘ord_pay_typ_id‘=>1, 69 ‘ord_cre_date‘=>date(‘Y-m-d H:i:s‘, time()) 70 ); 71 $obj = Order::create($info); 72 73 $ord_id = $obj->id; 74 $info = array( 75 ‘ord_id‘=>$ord_id, 76 ‘goo_id‘=>$spe_goo_id, 77 ‘goo_quantity‘=>1 78 79 ); 80 $obj_order_good = Order_good::create($info); 81 82 83 $add_quantity = 0; 84 $list = Goods::where([‘goo_id‘=>$spe_goo_id])->get()->toArray(); 85 foreach($list as $v) { 86 $add_quantity = $v[‘goo_quantity‘]; 87 } 88 89 var_dump(‘Order insert id:‘.$obj->id); 90 var_dump(‘Order_good insert id:‘.$obj_order_good->id); 91 92 if($add_quantity) { 93 $ret = Ecg_customer::where([‘ecg_cus_id‘=>$uid])->increment(‘ecg_cus_ava_times‘, $add_quantity); 94 if($ret) { 95 echo ‘increment add_quantity ‘.$add_quantity.‘ success!‘; 96 } else { 97 echo ‘increment add_quantity ‘.$add_quantity.‘ fail!‘; 98 } 99 } else { 100 echo ‘the goo_id :‘.$spe_goo_id.‘ of quantity is 0‘; 101 } 102 103 } 104 }
原文:http://www.cnblogs.com/dongruiha/p/6322658.html