hasGoods() public static method

public static hasGoods ( $id )
Ejemplo n.º 1
0
 public function actionAdd($id)
 {
     Yii::$app->response->format = Response::FORMAT_JSON;
     if (!Goods::find()->where(['id' => $id, 'store_id' => Yii::$app->user->identity->store_id, 'status' => [Goods::STATUS_NORMAL, Goods::STATUS_OFF_SHELVES]])->exists() || Purchase::hasGoods($id)) {
         throw new BadRequestHttpException('拒绝操作。');
     }
     $model = new Purchase();
     $model->goods_id = $id;
     $model->store_id = Yii::$app->user->identity->store_id;
     $model->count = 1;
     if ($model->save(false)) {
         return ['status' => 'success', 'data' => []];
     } else {
         return ['status' => 'fail', 'data' => ['message' => '加入失败。']];
     }
 }
Ejemplo n.º 2
0
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 '&yen; ' . $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 () {