where([ 'is_delete' => 0, 'store_id' => get_store_id(), 'is_show' => 1, ])->all(); return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'data' => $list, ], ]); } public function actionProductBatchList() { $start_time = get_params('dateStart'); $end_time = get_params('dateEnd'); $search_product_name_key = get_params('search_product_name_key'); $search_batch_name_key = get_params('search_batch_name_key'); $search_goods_name_key = get_params('search_goods_name_key'); $search_state = get_params('search_state', '-1'); $query = ProductBatch::find()->alias('pb') ->leftJoin(['p' => Product::tableName()], 'p.id=pb.product_id') ->leftJoin(['g' => Goods::tableName()], 'g.id=pb.goods_id') ->where([ 'pb.is_delete' => 0, 'pb.store_id' => get_store_id() ])->select(['pb.*', 'p.product_name', 'g.name as goods_name']); if (!empty($search_product_name_key)) { $query->andWhere(['like', 'p.product_name', $search_product_name_key]); } if (!empty($search_batch_name_key)) { $query->andWhere(['like', 'pb.batch_name', $search_batch_name_key]); } if (!empty($search_goods_name_key)) { $query->andWhere(['like', 'g.name', $search_goods_name_key]); } if ($search_state != -1) { $query->andWhere(['pb.state' => $search_state]); } if ($start_time) { $query->andWhere(['>=', 'pb.created_at', strtotime($start_time)]); } if ($end_time) { $query->andWhere(['<=', 'pb.created_at', strtotime($end_time)]); } $list = pagination_make($query); $list= $list['list']; foreach ($list as $k => $v) { $goods_id_list = [$v['goods_id']]; $list[$k]['goods_list'] = GoodsForm::getGoodsListById($goods_id_list); } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'data' => $list, 'pageNo' => $list['pageNo'], 'totalCount' => $list['totalCount'], ], ]); } public function actionProductBatchDel() { $id = get_params('id'); $product_batch = ProductBatch::findOne($id); $product_batch->is_delete = 1; if ($product_batch->save()) { return $this->asJson([ 'code' => 0, 'msg' => '删除成功' ]); }else { return $this->asJson([ 'code' => 1, 'msg' => $product_batch->getErrors(), ]); } } /** * 批量操作 * @return \yii\web\Response */ public function actionProductBatchOperate() { $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') { ProductBatch::updateAll(['is_show' => $status], ['in', 'id', $id]); } if ($type == 'delete') { $res= ProductBatch::updateAll(['is_delete' => $status], ['in', 'id', $id]); } return $this->asJson([ 'code' => 0, 'msg' => '更新成功' ]); } public function actionProductBatchEdit() { $store_id = get_store_id(); $id = post_params('id', 0); $batch_name = post_params('batch_name'); $product_id = post_params('product_id', 0); $goods_id = post_params('goods_id', 0); if ($id > 0) { $product_batch = ProductBatch::findOne($id); } else { $product_batch = new ProductBatch(); while (true) { $batch_number = date('YmdHis') . mt_rand(100000, 999999); $exist_batch_number = ProductBatch::find()->where(['batch_number' => $batch_number])->exists(); if (!$exist_batch_number) { break; } } $product_batch->batch_number = $batch_number; } $product_batch->store_id = $store_id; $product_batch->product_id = $product_id; $product_batch->goods_id = $goods_id; $product_batch->batch_name = $batch_name; if ($product_batch->save()) { return $this->asJson([ 'code' => 0, 'msg' => $id > 0 ? '编辑成功' : '添加成功', ]); }else{ return $this->asJson([ 'code' => 1, 'msg' => $product_batch->getErrors(), ]); } } }