| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\admin\controllers\product_traceability;
- use app\modules\admin\controllers\BaseController;
- use app\plugins\product_traceability\models\Product;
- use app\utils\QrCode;
- use yii\base\BaseObject;
- use yii\helpers\Json;
- class ProductController extends BaseController
- {
- public function actionProductList()
- {
- $start_time = get_params('dateStart');
- $end_time = get_params('dateEnd');
- $search_key = get_params('search_key');
- $search_is_show = get_params('search_is_show');
- $query = Product::find()->where([
- 'is_delete' => 0,
- 'store_id' => get_store_id()
- ]);
- if (!empty($search_key)) {
- $query->andWhere(['like', 'product_name', $search_key]);
- }
- if ($search_is_show != -1) {
- $query->andWhere(['is_show' => $search_is_show]);
- }
- if ($start_time) {
- $query->andWhere(['>=', 'created_at', strtotime($start_time)]);
- }
- if ($end_time) {
- $query->andWhere(['<=', 'created_at', strtotime($end_time)]);
- }
- $list = pagination_make($query);
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'data' => $list['list'],
- 'pageNo' => $list['pageNo'],
- 'totalCount' => $list['totalCount'],
- ],
- ]);
- }
- public function actionProductShow()
- {
- $id = post_params('id');
- $product = Product::findOne($id);
- $product->is_show = $product->is_show === 1 ? 0 : 1;
- if ($product->save()) {
- return $this->asJson([
- 'code' => 0,
- 'msg' => '修改成功'
- ]);
- }
- return $this->asJson([
- 'code' => 1,
- 'msg' => '修改失败',
- ]);
- }
- public function actionProductDel()
- {
- $id = get_params('id');
- $product = Product::findOne($id);
- $product->is_delete = 1;
- if ($product->save()) {
- return $this->asJson([
- 'code' => 0,
- 'msg' => '删除成功'
- ]);
- }
- return $this->asJson([
- 'code' => 1,
- 'msg' => '删除失败',
- ]);
- }
- /**
- * 批量操作
- * @return \yii\web\Response
- */
- public function actionProductBatch()
- {
- $id = post_params('id');
- $type = post_params('type');
- $status = post_params('status');
- if (empty($id) || !is_array($id)) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '参数有误'
- ]);
- }
- if (!in_array($status, [0, 1])) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '状态参数有误'
- ]);
- }
- if ($type == 'open' || $type == 'disabled') {
- Product::updateAll(['is_show' => $status], ['in', 'id', $id]);
- }
- if ($type == 'delete') {
- Product::updateAll(['is_delete' => $status], ['in', 'id', $id]);
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => '更新成功'
- ]);
- }
- public function actionProductEdit()
- {
- $store_id = get_store_id();
- $id = post_params('id', 0);
- $name = post_params('product_name');
- $is_show = post_params('is_show', 1);
- if ($id > 0) {
- $product = Product::findOne($id);
- } else {
- $product = new Product();
- }
- $product->store_id = $store_id;
- $product->product_name = $name;
- $product->is_show = $is_show;
- if ($product->save()) {
- return $this->asJson([
- 'code' => 0,
- 'msg' => $id > 0 ? '编辑成功' : '添加成功',
- ]);
- }else{
- return $this->asJson([
- 'code' => 1,
- 'msg' => $product->getErrors(),
- ]);
- }
- }
- }
|