Esempio n. 1
0
 public function genOrderId()
 {
     $orderId = 'OUT' . date('Ymd');
     $count = StoreOutstore::find()->where(['between', 'date', date('Y-m-d 00:00:00'), date('Y-m-d 23:59:59')])->count();
     return $orderId . str_pad($count + 1, 5, 0, STR_PAD_LEFT);
 }
Esempio n. 2
0
 public function actionConfirm()
 {
     $id = Yii::$app->request->getBodyParam('id');
     $model = StoreOutstore::findOne($id);
     if ($model === null) {
         $this->ajax_return(false, '找不到该订单');
     }
     if ($model->status == 'succ') {
         $this->ajax_return(true, '该订单已确认出库过了!');
     }
     if ($model->status == 'wait') {
         $trans = Yii::$app->db->beginTransaction();
         try {
             $model->status = 'succ';
             //更新宣传品的库存
             $list = StoreStoreDetail::getListByOrderId($model->order_id);
             $goodsUpdate = true;
             foreach ($list as $value) {
                 $goodsModel = StoreGoods::findOne($value->goods_id);
                 $goodsModel->count = $goodsModel->count - $value->count;
                 if ($goodsModel->count < 0) {
                     $this->ajax_return(true, '"' . $goodsModel->name . '"库存不足!');
                 }
                 if (!$goodsModel->save()) {
                     $goodsUpdate = false;
                 }
                 if ($goodsUpdate == false) {
                     break;
                 }
             }
             if ($model->save() && $goodsUpdate && StoreStoreDetail::updateAll(['status' => 'on'], 'order_id="' . $model->order_id . '"')) {
                 $trans->commit();
             } else {
                 $trans->rollBack();
             }
         } catch (Exception $e) {
             $trans->rollBack();
             $this->ajax_return(false, '数据异常');
         }
     }
     $this->ajax_return(true, '操作成功!');
 }