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(), 'pb.id' => $product_batch_id ])->select(['pb.*', 'p.product_name', 'g.name as goods_name'])->asArray()->one(); $goods_id_list = [$product_batch['goods_id']]; $product_batch['goods_list'] = GoodsForm::getGoodsListById($goods_id_list); $query = ProductBatchProcess::find()->alias('pbp') ->leftJoin(['u' => User::tableName()], 'u.id=pbp.process_user_id') ->leftJoin(['su' => SaasUser::tableName()],'su.mobile=u.binding') ->where([ 'pbp.is_delete' => 0, 'pbp.store_id' => get_store_id(), 'pbp.product_batch_id' => $product_batch_id, ])->select(['pbp.*', 'su.name',])->orderBy(['pbp.sort' => SORT_ASC]); $list = pagination_make($query); $list= $list['list']; foreach ($list as $k => $v){ $list[$k]['sheet_list'] = ProductBatchProcessSheet::find()->where(['store_id' =>get_store_id(), 'product_batch_process_id' => $v['id']])->asArray()->all(); } return [ 'code' => 0, 'msg' => 'success', 'data' => [ 'data' => $list, 'pageNo' => $list['pageNo'], 'totalCount' => $list['totalCount'], 'product_batch' => $product_batch ], ]; } public function actionProductBatchProcessDel() { $id = get_params('id'); $product_batch_process = ProductBatchProcess::findOne($id); $product_batch_process->is_delete = 1; if ($product_batch_process->save()) { $product_batch_process_form = ProductBatchProcessSheet::find()->where([ 'product_batch_process_id' => $product_batch_process->id, ])->one(); if($product_batch_process_form) { $product_batch_process_form->is_delete = 1; $product_batch_process_form->save(); } $product_batch_process_log = ProductBatchProcessLog::find()->where([ 'product_batch_id' => $product_batch_process->product_batch_id, 'product_batch_process_id' => $product_batch_process->id, ])->one(); if($product_batch_process_log) { $product_batch_process_log->is_delete = 1; $product_batch_process_log->save(); } return [ 'code' => 0, 'msg' => '删除成功' ]; }else { return [ 'code' => 1, 'msg' => $product_batch_process->getErrors(), ]; } } /** * 批量操作 * @return \yii\web\Response */ public function actionProductBatchProcessOperate() { $ids = post_params('id'); $type = post_params('type'); $status = post_params('status'); if (empty($ids) || !is_array($ids)) { 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]); foreach ($ids as $id){ $product_batch_process = ProductBatchProcess::findOne($id); $product_batch_process->is_delete = 1; if ($product_batch_process->save()) { $product_batch_process_form = ProductBatchProcessSheet::find()->where([ 'product_batch_process_id' => $product_batch_process->id, ])->one(); if ($product_batch_process_form) { $product_batch_process_form->is_delete = 1; $product_batch_process_form->save(); } $product_batch_process_log = ProductBatchProcessLog::find()->where([ 'product_batch_id' => $product_batch_process->product_batch_id, 'product_batch_process_id' => $product_batch_process->id, ])->one(); if ($product_batch_process_log) { $product_batch_process_log->is_delete = 1; $product_batch_process_log->save(); } } } } return [ 'code' => 0, 'msg' => '更新成功' ]; } public function actionProductBatchProcessEdit() { $form = new ProductBatchProcessForm(); $form->store_id = get_store_id(); $form->attributes = post_params(); return $form->save(); } }