public function actionCount($id) { Yii::$app->response->format = Response::FORMAT_JSON; $count = (int) Yii::$app->request->post('value', 1); $model = Purchase::findOne(['id' => $id, 'store_id' => Yii::$app->user->identity->store_id]); if (!$model || $count < 1 || $count > 500) { throw new BadRequestHttpException('参数错误。'); } $model->count = $count; if ($model->save(false)) { return ['status' => 'ok']; } else { return ['status' => 'no', 'msg' => '设置错误。']; } }
public function create($runValidation = true) { if ($runValidation && !$this->validate()) { return false; } if (empty($this->_purchaseList)) { return false; } $transaction = Yii::$app->db->beginTransaction(); try { if (Apply::find()->where(['store_id' => Yii::$app->user->identity->store_id, 'status' => [Apply::STATUS_PENDING, Apply::STATUS_REJECTED, Apply::STATUS_PASSED]])->exists()) { throw new \Exception('您采购历史中还有未完成的订单,不能继续申请.'); } $this->_apply = new Apply(); $this->_apply->generateApplySn(); $this->_apply->store_id = Yii::$app->user->identity->store_id; $this->_apply->status = Apply::STATUS_PENDING; $this->_apply->fee = Purchase::getVolumeByStoreId($this->_apply->store_id); $this->_apply->remark = $this->remark; if (!$this->_apply->save(false)) { throw new \Exception('创建申请失败!'); } foreach ($this->_purchaseList as $purchase) { if ($purchase->isExpired) { throw new \Exception("商品“{$purchase->goods->name}”已失效,请删除该商品然后继续。"); } $modelApplyGoods = ApplyGoods::createDuplicate($purchase->goods_id); $modelApplyGoods->apply_id = $this->_apply->id; $modelApplyGoods->count = $purchase->count; if (!$modelApplyGoods->save(false)) { throw new \Exception('记录商品清单失败!'); } } $modelApplyLog = new ApplyLog(); $modelApplyLog->apply_id = $this->_apply->id; $modelApplyLog->remark = '开始提交申请。'; if (!$modelApplyLog->save(false)) { throw new \Exception('商品申请记录失败!'); } Purchase::clear(Yii::$app->user->identity->store_id); $transaction->commit(); return true; } catch (\Exception $e) { $transaction->rollBack(); throw $e; } }
unset($statusList[Goods::STATUS_DELETED]); ?> <div class="row"> <div class="col-lg-12"> <?php Pjax::begin(); ?> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'tableOptions' => ['class' => 'table table-striped table-bordered table-center'], 'summaryOptions' => ['tag' => 'p', 'class' => 'text-right text-info'], 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['attribute' => 'name', 'headerOptions' => ['class' => 'col-md-2'], 'filterInputOptions' => ['class' => 'form-control input-sm']], ['attribute' => 'category_id', 'headerOptions' => ['class' => 'col-md-1'], 'filter' => Category::getKeyValuePairs(), 'filterInputOptions' => ['class' => 'form-control input-sm'], 'value' => function ($model, $key, $index, $column) { return $model->category->name; }], ['attribute' => 'price', 'headerOptions' => ['class' => 'col-md-1'], 'format' => 'html', 'filterInputOptions' => ['class' => 'form-control input-sm', 'title' => '支持运算符'], 'value' => function ($model, $key, $index, $column) { return '¥ ' . $model->price; }], ['attribute' => 'surplus', 'headerOptions' => ['class' => 'col-md-1'], 'filterInputOptions' => ['class' => 'form-control input-sm', 'title' => '支持运算符']], ['attribute' => 'sales', 'headerOptions' => ['class' => 'col-md-1'], 'filterInputOptions' => ['class' => 'form-control input-sm', 'title' => '支持运算符']], ['attribute' => 'status', 'format' => 'raw', 'filter' => $statusList, 'filterInputOptions' => ['class' => 'form-control input-sm'], 'headerOptions' => ['class' => 'col-md-1'], 'value' => function ($model, $key, $index, $column) { return Html::dropDownList('status', $model->status, $column->filter, ['data-id' => $model->id]); }], ['attribute' => 'created_at', 'format' => ['date', 'php:Y-m-d H:i'], 'filter' => DatePicker::widget(['model' => $searchModel, 'type' => DatePicker::TYPE_COMPONENT_APPEND, 'attribute' => 'date', 'options' => ['class' => 'input-sm'], 'pluginOptions' => ['autoclose' => true, 'format' => 'yyyy-mm-dd']]), 'headerOptions' => ['class' => 'col-md-3']], ['class' => 'yii\\grid\\ActionColumn', 'header' => '采购', 'headerOptions' => ['class' => 'col-md-1'], 'template' => '{purchase}', 'buttons' => ['purchase' => function ($url, $model, $key) { return Purchase::hasGoods($model->id) ? Html::button('已加入', ['class' => 'btn btn-default btn-xs btn-purchase active', 'data-id' => $model->id]) : Html::button('加入', ['class' => 'btn btn-default btn-xs btn-purchase', 'data-id' => $model->id]); }]], ['class' => 'yii\\grid\\ActionColumn', 'header' => '操作', 'headerOptions' => ['class' => 'col-md-1'], 'template' => '{update} {surplus} {delete}', 'buttons' => ['surplus' => function ($url, $model, $key) { return Html::a('<span class="glyphicon glyphicon-equalizer" aria-hidden="true"></span>', $url, ['title' => '库存变化记录']); }]]]]); ?> <?php Pjax::end(); ?> </div> </div> <?php $url = Url::to(['/goods/status']); $urlAdd = Url::to(['/purchase/add']); $urlDelete = Url::to(['/purchase/delete']); $js = <<<JS var handle = function () {