|
@@ -4,7 +4,9 @@ use App\Facades\Servers\WechatMini\Mini;
|
|
|
use App\Http\Requests\Admin\ScoreClockinActive as Request;
|
|
|
use App\Models\City;
|
|
|
use App\Models\Score\ClockinActive as Model;
|
|
|
+use App\Models\Score\Clockin as Clockin;
|
|
|
use App\Models\WeiBan\Tags as WeiBanTags;
|
|
|
+use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -209,5 +211,46 @@ class ScoreClockinActive extends Auth{
|
|
|
// 告知结果
|
|
|
return json_send(['code'=>'success','msg'=>'设置成功','path'=>'']);
|
|
|
}
|
|
|
-
|
|
|
+ /**
|
|
|
+ * 复制
|
|
|
+ *
|
|
|
+ * */
|
|
|
+ public function copy(Request $request,Model $Model,Clockin $Clockin){
|
|
|
+ // 验证参数
|
|
|
+ $request->scene('copy')->validate();
|
|
|
+ // 设置状态
|
|
|
+ $id = request('id',0);
|
|
|
+ $time = time();
|
|
|
+ // 查询
|
|
|
+ $data = $Model->where(['id'=>$id])->first()->toArray();
|
|
|
+ if (!$data) json_send(['code'=>'error','msg'=>'复制失败,活动不存在']);
|
|
|
+ $clockinList = $Clockin->getActiveList($id);
|
|
|
+ DB::beginTransaction();
|
|
|
+ try {
|
|
|
+ unset($data['id']);
|
|
|
+ //复制活动
|
|
|
+ $newId = $Model->add($data);
|
|
|
+ if (!$newId){
|
|
|
+ DB::rollBack();
|
|
|
+ return json_send(['code'=>'error','msg'=>'复制失败']);
|
|
|
+ }
|
|
|
+ if ($clockinList){
|
|
|
+ foreach ($clockinList as &$clockin){
|
|
|
+ $clockin['active_id'] = $newId;
|
|
|
+ $clockin['insert_time'] = $time;
|
|
|
+ $clockin['update_time'] = $time;
|
|
|
+ unset($clockin['id']);
|
|
|
+ }
|
|
|
+ $re = $Clockin->Query()->insert($clockinList);
|
|
|
+ if (!$re) return json_send(['code'=>'error','msg'=>'复制失败']);
|
|
|
+ }
|
|
|
+ DB::commit();
|
|
|
+ }catch (\Exception $e){
|
|
|
+ // 回退数据
|
|
|
+ DB::rollBack();
|
|
|
+ // 失败提示
|
|
|
+ return json_send(['code'=>'error','msg'=>'复制失败','data'=>['error'=>$e->getMessage().$e->getLine()]]);
|
|
|
+ }
|
|
|
+ return json_send(['code'=>'success','msg'=>'复制成功','path'=>'']);
|
|
|
+ }
|
|
|
}
|