laravel console handle 传参方法

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\Libs\wxpay\CLogFileHandler;
use App\Libs\wxpay\Log;
use App\Helpers\ReportHelper;
use App\Helpers\CommonHelper;
use App\Models\Ecg_customer;
use App\Models\Ecg_report;
use App\Models\Order;
use App\Models\Order_good;
use App\Models\Goods;

class AddUserCombo extends Command
{
    
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
     
    protected $signature = 'add_user_combo:run {--uid=} {--spe_goo_id=}'; //传参

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * php artisan add_user_combo:run --uid=88 --spe_goo_id=9
     *
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        
        //$uid = 219;
        $ord_typ_id = 1;
        //$spe_goo_id = 8;
        
        $uid = $this->option('uid');
        $spe_goo_id = $this->option('spe_goo_id');
        
        $info = array(
            'ord_typ_id'=>$ord_typ_id,
            'out_trade_no'=>CommonHelper::get_order_sn(),
            'use_id'=>$uid, 
            'ord_sta_id'=>1, 
            'ord_display'=>0, 
            'ord_pay_sta_id'=>1, 
            'ord_pay_typ_id'=>1, 
            'ord_cre_date'=>date('Y-m-d H:i:s', time()) 
        );
        $obj = Order::create($info);
        
        $ord_id = $obj->id;
        $info = array(
            'ord_id'=>$ord_id,
            'goo_id'=>$spe_goo_id,
            'goo_quantity'=>1
            
        );
        $obj_order_good = Order_good::create($info);
        
        
        $add_quantity = 0;
        $list = Goods::where(['goo_id'=>$spe_goo_id])->get()->toArray();
        foreach($list as $v) {
            $add_quantity = $v['goo_quantity'];
        }

        var_dump('Order insert id:'.$obj->id);
        var_dump('Order_good insert id:'.$obj_order_good->id);
        
        if($add_quantity) {
            $ret = Ecg_customer::where(['ecg_cus_id'=>$uid])->increment('ecg_cus_ava_times', $add_quantity);
            if($ret) {
                echo 'increment add_quantity '.$add_quantity.' success!';
            } else {
                echo 'increment add_quantity '.$add_quantity.' fail!';
            }
        } else {
            echo 'the goo_id :'.$spe_goo_id.' of quantity is 0';
        }
        
    }
}

 

posted on 2017-01-20 13:54  dongruiha  阅读(1704)  评论(0编辑  收藏  举报

导航