예제 #1
0
 public function getGoods($status = '')
 {
     $page = Yii::$app->request->get('page', 0);
     $page = $page < 0 ? 0 : $page - 1;
     $limit = Yii::$app->request->get('limit', 25);
     $name = Yii::$app->request->get('name');
     $status = $status != '' ? $status : Yii::$app->request->get('status');
     $hasMore = intval(Yii::$app->request->get('has_more'));
     $sorts = json_decode(trim(Yii::$app->request->get('sort')), true);
     $query = StoreGoods::find()->filterWhere(['status' => $status])->andFilterWhere(['like', 'name', $name]);
     if ($hasMore == 1) {
         $query->andFilterWhere(['>', 'count', 0]);
     }
     $countQuery = clone $query;
     $pagination = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => $limit]);
     if ($sorts != null) {
         foreach ($sorts as $sort) {
             $query->addOrderBy([$sort['property'] => $sort['direction'] == 'ASC' ? SORT_ASC : SORT_DESC]);
         }
     } else {
         $query->addOrderBy(['id' => SORT_DESC]);
     }
     $model = $query->offset($pagination->offset)->limit($limit)->all();
     return ['count' => $countQuery->count(), 'model' => $model];
 }
예제 #2
0
 public function actionDelete()
 {
     $id = Yii::$app->request->getBodyParam('id');
     if ($id == '' || ($model = StoreGoods::findOne($id)) === null) {
         $this->ajax_return(false, '找不到该数据!');
     }
     $model->deleted = 1;
     if ($model->update()) {
         $this->ajax_return(true);
     } else {
         $this->ajax_return(false, '删除失败!');
     }
 }
예제 #3
0
 public function getGoods()
 {
     return $this->hasOne(StoreGoods::className(), ['id' => 'goods_id']);
 }
예제 #4
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, '操作成功!');
 }