where([ 'is_delete' => 0, 'store_id' => get_store_id(), 'is_show' => 1, ])->all(); return [ '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', trim($search_product_name_key)]); } if (!empty($search_batch_name_key)) { $query->andWhere(['like', 'pb.batch_name', trim($search_batch_name_key)]); } if (!empty($search_goods_name_key)) { $query->andWhere(['like', 'g.name', trim($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, true, 'id desc'); $list= $list['list']; foreach ($list as $k => $v) { $goods_id_list = [$v['goods_id']]; $list[$k]['goods_list'] = GoodsForm::getGoodsListById($goods_id_list); } return [ '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 [ 'code' => 0, 'msg' => '删除成功' ]; }else { return [ '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 [ 'code' => 1, 'msg' => '参数有误' ]; } if (!in_array($status, [0, 1])) { return [ '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 [ '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; } $exist_batch_goods = ProductBatch::find()->where(['goods_id' => $goods_id, 'is_delete' => 0])->one(); if ($exist_batch_goods && $exist_batch_goods->id != $id) { return [ 'code' => 1, 'msg' => '该商品已经存在,不能重复添加', ]; } $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 [ 'code' => 0, 'msg' => $id > 0 ? '编辑成功' : '添加成功', ]; }else{ return [ 'code' => 1, 'msg' => $product_batch->getErrors(), ]; } } /** * 获取小程序二维码 */ public function actionGetQr () { $store_id = get_store_id(); $product_batch_id = get_params('product_batch_id', 0); $md_id = get_md_id(); $scene = "pb_id={$product_batch_id}&md_id={$md_id}&store={$store_id}"; $res = ShareQrcode::wxQrcode('source/history/history', $scene); if (isset($res['code']) && $res['code'] == 1) { return [ 'code' => 1, 'msg' => $res['response']['errmsg'], ]; } return [ 'code' => 0, 'data' => [ 'qr_url' => $res['url_path'] ] ]; } public function actionGetAllGoodsList() { return SearchAllGoodsForm::getList(get_params()); } }