public function actionDetail($id) { /* @var $model Store */ $model = Store::findOne($id); if (!$model) { throw new BadRequestHttpException('未找到该营业点!'); } if ($model->status === Store::STATUS_DISABLED) { throw new BadRequestHttpException('该店铺已被禁用,请重新选择!'); } $data['store'] = $model->toArray(['id', 'name', 'school_id', 'address', 'cellphone', 'telephone', 'notice', 'status', 'hours', 'has_book', 'has_down', 'has_gift', 'has_least', 'down_upper', 'down_val', 'gift_upper', 'gift_val', 'least_val', 'created_at']); $data['store']['downMsg'] = $model->downMsg; $data['store']['giftMsg'] = $model->giftMsg; $data['categories'] = Category::getKeyValuePairs(); foreach ($data['categories'] as $key => $name) { $goodsList = $model->getGoods($key)->all(); if ($goodsList) { foreach ($goodsList as $goods) { $goodsArr = $goods->toArray(); $data['goodsList'][$key][] = $goodsArr; } } else { $data['goodsList'][$key] = []; } } return $data; }
public function actionLoadGoods($id, $category = 'all', $q = '') { $offset = (int) Yii::$app->request->post('offset'); Yii::$app->response->format = Response::FORMAT_JSON; /* @var $model Store */ $model = Store::findOne(['id' => $id, 'status' => [Store::STATUS_ACTIVE, Store::STATUS_REST]]); if (!$model) { throw new NotFoundHttpException('未找到该营业点!'); } if ($q !== '') { $query = $model->getGoods()->andWhere(['or', ['like', 'name', $q], ['like', 'description', $q]]); } else { $modelCate = $category === 'all' ? null : Category::findOne(['slug' => $category]); if ($modelCate) { $query = $model->getGoods($modelCate->id); } else { $query = $model->getGoods(); } } $limit = 8; $goodsList = $query->offset($offset)->limit($limit)->all(); $output = ['status' => 'ok', 'html' => '', 'length' => count($goodsList)]; $output['end'] = $output['length'] < $limit; foreach ($goodsList as $goods) { $output['html'] .= $this->renderPartial('_item', ['goods' => $goods, 'lazy' => false]); } return $output; }
public function __construct($id, $config = []) { $this->_store = Store::findOne($id); if (!$this->_store) { throw new InvalidParamException('未找到该店铺!'); } if ($this->_store->status === Store::STATUS_DISABLED) { throw new InvalidParamException('该店铺已禁用!'); } parent::__construct($config); }
/** * @inheritdoc */ public function init() { $schoolId = Yii::$app->request->cookies['schoolId']; $storeId = Yii::$app->request->cookies['storeId']; if ($schoolId) { Yii::$app->params['schoolModel'] = School::findOne($schoolId); } if ($storeId) { Yii::$app->params['storeModel'] = Store::findOne($storeId); } }
/** * Finds the Store model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Store the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Store::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
$this->title = '营业点用户列表'; ?> <p> <?php echo Html::a('<i class="fa fa-plus"></i> 添加营业点用户', ['member/add'], ['class' => 'btn btn-primary']); ?> </p> <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', 'headerOptions' => ['class' => '']], ['attribute' => 'store_id', 'headerOptions' => ['class' => 'col-md-4'], 'filterInputOptions' => ['class' => 'form-control input-sm'], 'value' => function ($model, $key, $index, $column) { return $model->store->school->name . '-' . $model->store->name; }, 'filter' => Select2::widget(['model' => $searchModel, 'initValueText' => ($store = Store::findOne($searchModel->store_id)) ? $store->name : '', 'attribute' => 'store_id', 'size' => Select2::SMALL, 'theme' => Select2::THEME_KRAJEE, 'options' => ['placeholder' => '搜索店铺名称...'], 'pluginOptions' => ['allowClear' => true, 'minimumInputLength' => 3, 'ajax' => ['url' => Url::to(['/store/name-filter']), 'dataType' => 'json', 'data' => new JsExpression('function(params) { return {q:params.term}; }')], 'escapeMarkup' => new JsExpression('function (markup) { return markup; }'), 'templateResult' => new JsExpression('function (store) { return store.text; }'), 'templateSelection' => new JsExpression('function (store) { return store.text; }')]])], ['attribute' => 'username', 'headerOptions' => ['class' => 'col-md-1'], 'filterInputOptions' => ['class' => 'form-control input-sm']], ['attribute' => 'real_name', 'headerOptions' => ['class' => 'col-md-1'], 'filterInputOptions' => ['class' => 'form-control input-sm']], ['attribute' => 'gender', 'filter' => Member::getGenderList(), 'filterInputOptions' => ['class' => 'form-control input-sm'], 'headerOptions' => ['class' => 'col-md-1'], 'value' => function ($model, $key, $index, $column) { return $model->genderMsg; }], ['attribute' => 'mobile', 'headerOptions' => ['class' => 'col-md-1'], 'filterInputOptions' => ['class' => 'form-control input-sm']], ['attribute' => 'status', 'format' => 'raw', 'filter' => Member::getStatusList(), 'filterInputOptions' => ['class' => 'form-control input-sm'], 'headerOptions' => ['class' => 'col-md-1'], 'value' => function ($model, $key, $index, $column) { return Html::dropDownList('status', $model->status, Member::getStatusList(), ['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-2']], ['class' => 'yii\\grid\\ActionColumn', 'header' => '操作', 'headerOptions' => ['class' => 'col-md-1'], 'template' => '{update}']]]); ?> <?php Pjax::end(); ?> </div> </div> <?php $url = Url::to(['/member/status']); $js = <<<JS var handle = function () { var id = \$(this).attr('data-id');
public function actionRealFee() { Yii::$app->response->format = Response::FORMAT_JSON; $storeId = Yii::$app->request->post('storeId', 0); $preferential = Yii::$app->request->post('preferential'); $newDown = Yii::$app->request->post('newdown'); $payment = Yii::$app->request->post('payment'); /* @var $model Store */ $model = Store::findOne($storeId); if (!$model) { return ['status' => 'no']; } $realFee = $fee = Yii::$app->user->identity->getCartGoodsRealVolume($storeId); switch ($preferential) { case Order::PREFERENTIAL_DOWN: if ($model->has_down && $fee >= $model->down_upper) { $realFee = bcsub($realFee, $model->down_val, 2); } break; default: break; } if (Yii::$app->params['enableNewDown'] && $newDown && $fee >= Yii::$app->params['newDownUpper'] && Yii::$app->user->identity->has_new_down) { $realFee = bcsub($realFee, Yii::$app->params['newDownVal'], 2); if ($realFee < 0) { $realFee = '0.00'; } } return ['status' => 'ok', 'realFee' => $realFee]; }
<?php use yii\helpers\Url; use yii\helpers\Html; use yii\bootstrap\ActiveForm; use yii\web\JsExpression; use kartik\select2\Select2; use common\models\Store; $this->title = $model->isNewRecord ? '添加标签' : '更新标签'; ?> <div class="row"> <div class="col-lg-6"> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'store_id')->widget(Select2::className(), ['initValueText' => ($store = Store::findOne($model->store_id)) ? $store->name : '', 'theme' => Select2::THEME_KRAJEE, 'options' => ['placeholder' => '搜索店铺名称...'], 'pluginOptions' => ['allowClear' => true, 'minimumInputLength' => 3, 'ajax' => ['url' => Url::to(['/store/name-filter']), 'dataType' => 'json', 'data' => new JsExpression('function(params) { return {q:params.term}; }')], 'escapeMarkup' => new JsExpression('function (markup) { return markup; }'), 'templateResult' => new JsExpression('function (store) { return store.text; }'), 'templateSelection' => new JsExpression('function (store) { return store.text; }')]]); ?> <?php echo $form->field($model, 'name'); ?> <div class="form-group"> <?php echo Html::submitButton('<i class="fa fa-floppy-o"></i> 保存', ['class' => 'btn btn-primary']); ?> </div> <?php ActiveForm::end(); ?> </div> </div>
/** * 将商品从一个店铺克隆到另一个店铺 * * @param string $from 源商品所在店铺ID * @param string $to 目标店铺ID * @param string $category 过滤商品类型 * @param string $status 过滤商品状态 * @return string */ public function actionCloneAll($from, $to, $category = 'all', $status = 'all') { $modelFrom = Store::findOne($from); $modelTo = Store::findOne($to); if (!$modelFrom || !$modelTo) { echo "The parameter error.\n"; return static::EXIT_CODE_ERROR; } if ($modelFrom->type !== $modelTo->type) { if (!static::confirm("The types of two stores are not the same, continue?")) { echo "Cancelled.\n"; return static::EXIT_CODE_NORMAL; } } unset($modelFrom, $modelTo); $query = Goods::find()->where(['store_id' => $from]); if ($category !== 'all') { $modelCate = Category::findOne(['slug' => $category]); if ($modelCate) { $query->andWhere(['category_id' => $modelCate->id]); unset($modelCate); } else { echo "The category \"{$category}\" can not be exists.\n"; return static::EXIT_CODE_ERROR; } } if ($status !== 'all') { if (in_array($status, [Goods::STATUS_NORMAL, Goods::STATUS_OFF_SHELVES, Goods::STATUS_DELETED])) { $query->andWhere(['status' => $status]); } else { echo "The status was error.\n"; return static::EXIT_CODE_ERROR; } } if (($count = $query->count()) > 0) { if (!static::confirm("Next we will clone {$count} goods, are you sure?")) { echo "Cancelled.\n"; return static::EXIT_CODE_NORMAL; } } else { echo "The goods count is 0.\n"; return static::EXIT_CODE_NORMAL; } $goodsList = $query->asArray()->all(); $time = time(); $sql = "INSERT INTO {{%goods}} (name, store_id, category_id, cover, price, price_original, cost, description, status, surplus, sales, unit, is_new, is_hot, is_promotion, created_at, updated_at) VALUES (:name, :store_id, :category_id, :cover, :price, :price_original, :cost, :description, :status, :surplus, :sales, :unit, :is_new, :is_hot, :is_promotion, :created_at, :updated_at)"; $sql2 = "INSERT INTO {{%goods_img}} (name, goods_id) VALUES (:name, :goods_id)"; $sql3 = "INSERT INTO {{%goods_surplus}} (goods_id, surplus_before, amount, surplus_after, remark, created_at, updated_at) VALUES (:goods_id, :surplus_before, :amount, :surplus_after, :remark, :created_at, :updated_at)"; $transaction = Yii::$app->db->beginTransaction(); try { foreach ($goodsList as $goods) { Yii::$app->db->createCommand($sql, [':name' => $goods['name'], ':store_id' => $to, ':category_id' => $goods['category_id'], ':cover' => $goods['cover'], ':price' => $goods['price'], ':price_original' => $goods['price_original'], ':cost' => $goods['cost'], ':description' => $goods['description'], ':status' => $goods['status'], ':surplus' => $goods['surplus'], ':sales' => '0', ':unit' => $goods['unit'], ':is_new' => $goods['is_new'], ':is_hot' => $goods['is_hot'], ':is_promotion' => $goods['is_promotion'], ':created_at' => $time, ':updated_at' => $time])->execute(); $goodsId = Yii::$app->db->getLastInsertID(); $goodsImgList = GoodsImg::find()->where(['goods_id' => $goods['id']])->asArray()->all(); foreach ($goodsImgList as $goodsImg) { Yii::$app->db->createCommand($sql2, [':name' => $goodsImg['name'], ':goods_id' => $goodsId])->execute(); } Yii::$app->db->createCommand($sql3, [':goods_id' => $goodsId, ':surplus_before' => 0, ':amount' => $goods['surplus'], ':surplus_after' => $goods['surplus'], ':remark' => '初始化库存。', ':created_at' => $time, ':updated_at' => $time])->execute(); } $transaction->commit(); echo "Success!\n"; return static::EXIT_CODE_NORMAL; } catch (\Exception $e) { $transaction->rollBack(); echo $e->getMessage(); return static::EXIT_CODE_ERROR; } }
public function actionNameFilter($q = null, $id = null) { Yii::$app->response->format = Response::FORMAT_JSON; $output = ['results' => ['id' => '', 'text' => '']]; if (!is_null($q)) { $sql = 'SELECT t0.id, CONCAT(t1.name, \'-\', t0.name) AS text FROM ' . Store::tableName() . ' AS t0 LEFT JOIN ' . School::tableName() . ' AS t1 ON t0.school_id = t1.id WHERE t0.name LIKE :like ORDER BY t0.school_id ASC LIMIT 25'; $output['results'] = Yii::$app->db->createCommand($sql, [':like' => "%{$q}%"])->queryAll(); } elseif ($id > 0 && ($store = Store::findOne($id))) { $output['results'] = ['id' => $id, 'text' => $store->school->name . '-' . $store->name]; } return $output; }
use yii\helpers\Url; use yii\helpers\Html; use yii\widgets\Pjax; use yii\grid\GridView; use yii\web\JsExpression; use kartik\date\DatePicker; use kartik\select2\Select2; use common\models\Store; //use himiklab\sortablegrid\SortableGridView; $this->title = '标签列表'; ?> <p> <?php echo Html::a('<i class="fa fa-plus"></i> 添加标签', ['tag/add'], ['class' => 'btn btn-primary']); ?> </p> <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', 'headerOptions' => ['class' => 'col-md-1']], ['attribute' => 'name', 'headerOptions' => ['class' => 'col-md-2'], 'filterInputOptions' => ['class' => 'form-control input-sm']], ['attribute' => 'store_id', 'headerOptions' => ['class' => 'col-md-5'], 'filterInputOptions' => ['class' => 'form-control input-sm'], 'value' => function ($model, $key, $index, $column) { return $model->store->school->name . '-' . $model->store->name; }, 'filter' => Select2::widget(['model' => $searchModel, 'initValueText' => ($store = Store::findOne($searchModel->store_id)) ? $store->name : '', 'attribute' => 'store_id', 'size' => Select2::SMALL, 'theme' => Select2::THEME_KRAJEE, 'options' => ['placeholder' => '搜索店铺名称...'], 'pluginOptions' => ['allowClear' => true, 'minimumInputLength' => 3, 'ajax' => ['url' => Url::to(['/store/name-filter']), 'dataType' => 'json', 'data' => new JsExpression('function(params) { return {q:params.term}; }')], 'escapeMarkup' => new JsExpression('function (markup) { return markup; }'), 'templateResult' => new JsExpression('function (store) { return store.text; }'), 'templateSelection' => new JsExpression('function (store) { return store.text; }')]])], ['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' => '{update} {delete}']]]); ?> <?php Pjax::end(); ?> </div> </div>