where([ 'is_delete' => 0, 'store_id' => get_store_id() ]); if (!empty($search_key)) { $query->andWhere(['like', 'product_name', trim($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 [ '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 [ 'code' => 0, 'msg' => '修改成功' ]; } return [ 'code' => 1, 'msg' => '修改失败', ]; } public function actionProductDel() { $id = get_params('id'); $product = Product::findOne($id); $product->is_delete = 1; if ($product->save()) { return [ 'code' => 0, 'msg' => '删除成功' ]; } return [ '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 [ 'code' => 1, 'msg' => '参数有误' ]; } if (!in_array($status, [0, 1])) { return [ '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 [ '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 [ 'code' => 0, 'msg' => $id > 0 ? '编辑成功' : '添加成功', ]; }else{ return [ 'code' => 1, 'msg' => $product->getErrors(), ]; } } }