zoukankan      html  css  js  c++  java
  • laravel console handle 传参方法

    <?php
    
    namespace AppConsoleCommands;
    
    use IlluminateConsoleCommand;
    use AppLibswxpayCLogFileHandler;
    use AppLibswxpayLog;
    use AppHelpersReportHelper;
    use AppHelpersCommonHelper;
    use AppModelsEcg_customer;
    use AppModelsEcg_report;
    use AppModelsOrder;
    use AppModelsOrder_good;
    use AppModelsGoods;
    
    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';
            }
            
        }
    }
  • 相关阅读:
    散列函数的构造方法
    散列表(哈希表)查找
    散列表,哈希表,散列表查找法
    多路查找树之2-3-4树和B树
    多路查找树之2-3树的删除原理
    多路查找树之2-3树的插入原理
    多路查找树之2-3树
    字典:当索引不好用时2
    字典:当索引不好用时
    平衡二叉树的实现原理(代码实现)- 数据结构和算法78
  • 原文地址:https://www.cnblogs.com/dongruiha/p/6322658.html
Copyright © 2011-2022 走看看