|
@@ -18,7 +18,7 @@ class RegimentActive extends Auth{
|
|
|
protected function _initialize(){
|
|
|
parent::_initialize();
|
|
|
$this->assign('breadcrumb1','拼团活动');
|
|
|
- $this->assign('breadcrumb2','拼团活动列表');
|
|
|
+ $this->assign('breadcrumb2','活动列表');
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -32,16 +32,15 @@ class RegimentActive extends Auth{
|
|
|
$map = [];
|
|
|
// 组合条件
|
|
|
if( $name ) $map[] = ['regiment_active.name','=',$name];
|
|
|
- $select = ['regiment_active.*','product.name as product_name'];
|
|
|
// 查询数据
|
|
|
$list = $Model->query()
|
|
|
- ->join('product','product.id','=','regiment_active.product_id')
|
|
|
- ->where($map)
|
|
|
- ->select($select)
|
|
|
- ->orderByDesc('regiment_active.id')
|
|
|
- ->paginate(config('page_num',10));
|
|
|
+ ->join('product','product.id','=','regiment_active.product_id')
|
|
|
+ ->where($map)
|
|
|
+ ->select(['regiment_active.*','product.name as product_name'])
|
|
|
+ ->orderByDesc('regiment_active.id')
|
|
|
+ ->paginate(config('page_num',10));
|
|
|
// 循环处理数据
|
|
|
- foreach ($list as $key => &$value) {
|
|
|
+ foreach ($list as &$value) {
|
|
|
$value['code'] = $Model->idToCode($value['id']);
|
|
|
}
|
|
|
// 分配数据
|
|
@@ -76,65 +75,65 @@ class RegimentActive extends Auth{
|
|
|
$data['start_time'] = $data['start_time'] ? strtotime($data['start_time']) : 0;
|
|
|
$data['end_time'] = $data['end_time'] ? strtotime($data['end_time']) : 0;
|
|
|
$data['participation_number'] = request('participation_number',0);
|
|
|
- $data['open_people'] = request('open_people',1);
|
|
|
- $data['partake_people'] = request('partake_people',1);
|
|
|
- $data['exceed_people'] = request('exceed_people',1);
|
|
|
- $data['automatic'] = request('automatic',1);
|
|
|
- $data['virtually'] = request('virtually',1);
|
|
|
+ $data['open_people'] = request('open_people',0);
|
|
|
+ $data['partake_people'] = request('partake_people',0);
|
|
|
+ $data['exceed_people'] = request('exceed_people',0);
|
|
|
+ $data['automatic'] = request('automatic',0);
|
|
|
+ $data['virtually'] = request('virtually',0);
|
|
|
$data['status'] = 1;
|
|
|
- $where = [
|
|
|
- ['status','=', 1],
|
|
|
- ['product_id','=', $data['product_id']],
|
|
|
- ['end_time','>=', time()]
|
|
|
- ];
|
|
|
- $product_res = $Model::query()->where($where)->first();
|
|
|
+ // 核对产品
|
|
|
+ $product_res = $Model::query()->where([['status','=', 1],['product_id','=', $data['product_id']],['end_time','>=', time()]])->first();
|
|
|
+ // 提示
|
|
|
if ($product_res) return json_send(['code'=>'error','msg'=>'该产品正在参加拼团活动']);
|
|
|
// 写入数据表
|
|
|
$id = $Model->add($data);
|
|
|
// 如果操作失败
|
|
|
if( !$id ) return json_send(['code'=>'error','msg'=>'新增失败']);
|
|
|
//商户开团
|
|
|
- if ($data['automatic'] == 1){
|
|
|
- $regimentData = [
|
|
|
- 'custom_uid' => 0,
|
|
|
- 'active_id' => $id,
|
|
|
- 'product_id' => $data['product_id'],
|
|
|
- 'status' => 1,
|
|
|
- 'start_time' => $data['start_time'],
|
|
|
- 'end_time' => $data['start_time'] + $data['expiration']*60*60,
|
|
|
- 'update_time' => time(),
|
|
|
- 'insert_time' => time(),
|
|
|
- ];
|
|
|
- $regimentRes = Regiment::query()->where($where)->insert($regimentData);
|
|
|
- if (!$regimentRes) return json_send(['code'=>'error','msg'=>'商户开团失败']);
|
|
|
+ if ($data['automatic'] == 1 ) {
|
|
|
+ // 开团信息
|
|
|
+ $regimentData = [
|
|
|
+ 'custom_uid' => 0,
|
|
|
+ 'active_id' => $id,
|
|
|
+ 'product_id' => $data['product_id'],
|
|
|
+ 'status' => 1,
|
|
|
+ 'start_time' => $data['start_time'],
|
|
|
+ 'end_time' => $data['start_time'] + $data['expiration']*60*60,
|
|
|
+ 'update_time' => time(),
|
|
|
+ 'insert_time' => time(),
|
|
|
+ ];
|
|
|
+ // 开团
|
|
|
+ $regimentRes = Regiment::query()->insert($regimentData);
|
|
|
+ // 开团结果
|
|
|
+ if (!$regimentRes) return json_send(['code'=>'error','msg'=>'商户开团失败']);
|
|
|
}
|
|
|
// 记录行为
|
|
|
$this->addAdminHistory(admin('uid'),$Model->getTable(),$id,1,[],$data);
|
|
|
// 告知结果
|
|
|
- return json_send(['code'=>'success','msg'=>'新增成功','action'=>'add']);
|
|
|
+ return json_send(['code'=>'success','msg'=>'新增成功','action'=>'add']);
|
|
|
}
|
|
|
// 标签列表
|
|
|
- $tagList = [];
|
|
|
- $cityList = [];
|
|
|
+ $tagList = [];
|
|
|
+ $cityList = [];
|
|
|
// 分配数据
|
|
|
$this->assign('cityList',$cityList);
|
|
|
$this->assign('tagList',$tagList);
|
|
|
$this->assign('crumbs','新增');
|
|
|
// 加载模板
|
|
|
- return $this->fetch();
|
|
|
+ return $this->fetch();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 修改
|
|
|
*
|
|
|
* */
|
|
|
- public function edit(Request $request,Model $Model,Product $Product){
|
|
|
+ public function edit(Request $request,Model $Model,Product $Product,Regiment $Regiment){
|
|
|
// 接收参数
|
|
|
- $id = request('id',0);
|
|
|
+ $id = request('id',0);
|
|
|
// 查询用户
|
|
|
- $oldData = $Model->where(['id'=>$id])->first()->toArray();
|
|
|
+ $oldData = $Model->where(['id'=>$id])->first()->toArray();
|
|
|
// 修改
|
|
|
- if(request()->isMethod('post')){
|
|
|
+ if(request()->isMethod('post')) {
|
|
|
// 验证参数
|
|
|
$request->scene('edit')->validate();
|
|
|
// 接收数据
|
|
@@ -153,27 +152,51 @@ class RegimentActive extends Auth{
|
|
|
$data['start_time'] = $data['start_time'] ? strtotime($data['start_time']) : 0;
|
|
|
$data['end_time'] = $data['end_time'] ? strtotime($data['end_time']) : 0;
|
|
|
$data['participation_number'] = request('participation_number',0);
|
|
|
- $data['open_people'] = request('open_people',1);
|
|
|
- $data['partake_people'] = request('partake_people',1);
|
|
|
- $data['exceed_people'] = request('exceed_people',1);
|
|
|
- $data['automatic'] = request('automatic',1);
|
|
|
- $data['virtually'] = request('virtually',1);
|
|
|
+ $data['open_people'] = request('open_people',0);
|
|
|
+ $data['partake_people'] = request('partake_people',0);
|
|
|
+ $data['exceed_people'] = request('exceed_people',0);
|
|
|
+ $data['automatic'] = request('automatic',0);
|
|
|
+ $data['virtually'] = request('virtually',0);
|
|
|
+ $data['status'] = 1;
|
|
|
+ // 核对产品
|
|
|
+ $product_res = $Model::query()->where([['status','=', 1],['product_id','=', $data['product_id']],['end_time','>=', time()]])->first();
|
|
|
+ // 提示
|
|
|
+ if ($product_res) return json_send(['code'=>'error','msg'=>'该产品正在参加拼团活动']);
|
|
|
// 写入数据表
|
|
|
- $result = $Model->edit($id,$data);
|
|
|
+ $id = $Model->add($data);
|
|
|
// 如果操作失败
|
|
|
- if( !$result ) return json_send(['code'=>'error','msg'=>'修改失败']);
|
|
|
+ if( !$id ) return json_send(['code'=>'error','msg'=>'新增失败']);
|
|
|
+ //商户开团
|
|
|
+ if ($data['automatic'] == 1 ) {
|
|
|
+ // 开团信息
|
|
|
+ $regimentData = [
|
|
|
+ 'custom_uid' => 0,
|
|
|
+ 'active_id' => $id,
|
|
|
+ 'product_id' => $data['product_id'],
|
|
|
+ 'status' => 1,
|
|
|
+ 'start_time' => $data['start_time'],
|
|
|
+ 'end_time' => $data['start_time'] + $data['expiration']*60*60,
|
|
|
+ 'update_time' => time(),
|
|
|
+ 'insert_time' => time(),
|
|
|
+ ];
|
|
|
+ // 开团
|
|
|
+ $regimentRes = Regiment::query()->insert($regimentData);
|
|
|
+ // 开团结果
|
|
|
+ if (!$regimentRes) return json_send(['code'=>'error','msg'=>'商户开团失败']);
|
|
|
+ }
|
|
|
// 记录行为
|
|
|
$this->addAdminHistory(admin('uid'),$Model->getTable(),$id,2,$oldData,$data);
|
|
|
// 告知结果
|
|
|
- return json_send(['code'=>'success','msg'=>'修改成功','action'=>'edit']);
|
|
|
+ return json_send(['code'=>'success','msg'=>'修改成功','action'=>'edit']);
|
|
|
}
|
|
|
// 错误告知
|
|
|
- if( !$oldData ) return $this->error('查无数据');
|
|
|
- $oldData['product_code'] = $Product->idToCode($oldData['product_id']);
|
|
|
+ if( !$oldData ) return $this->error('查无数据');
|
|
|
+ // 返回结果
|
|
|
+ $oldData['product_code'] = $Product->idToCode($oldData['product_id']);
|
|
|
$this->assign('oldData',$oldData);
|
|
|
$this->assign('crumbs','修改');
|
|
|
// 加载模板
|
|
|
- return $this->fetch();
|
|
|
+ return $this->fetch();
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -199,48 +222,79 @@ class RegimentActive 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']);
|
|
|
- $data['status'] = 1;
|
|
|
- $data['name'] = $data['name'].'复制';
|
|
|
- //复制活动
|
|
|
- $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'=>'复制失败']);
|
|
|
+ public function copy(Request $request,Model $Model,Product $Product){
|
|
|
+ // 接收参数
|
|
|
+ $id = request('id',0);
|
|
|
+ // 查询用户
|
|
|
+ $oldData = $Model->where(['id'=>$id])->first()->toArray();
|
|
|
+ // 修改
|
|
|
+ if(request()->isMethod('post')) {
|
|
|
+ // 验证参数
|
|
|
+ $request->scene('edit')->validate();
|
|
|
+ // 接收数据
|
|
|
+ $product_code = request('product_code','');
|
|
|
+ $data['product_id'] = $Product->codeToId($product_code);
|
|
|
+ if (!$data['product_id']) return json_send(['code'=>'error','msg'=>'产品不存在']);
|
|
|
+ $data['regiment_price'] = request('regiment_price',0);
|
|
|
+ $data['quota'] = request('quota','');
|
|
|
+ $data['name'] = request('name','');
|
|
|
+ $data['number'] = request('number',0);
|
|
|
+ $expiration_day = request('expiration_day',0);
|
|
|
+ $expiration_hours = request('expiration_hours',0);
|
|
|
+ $data['expiration'] = $expiration_day * 24 + $expiration_hours;
|
|
|
+ $data['start_time'] = request('start_time','');
|
|
|
+ $data['end_time'] = request('end_time','');
|
|
|
+ $data['start_time'] = $data['start_time'] ? strtotime($data['start_time']) : 0;
|
|
|
+ $data['end_time'] = $data['end_time'] ? strtotime($data['end_time']) : 0;
|
|
|
+ $data['participation_number'] = request('participation_number',0);
|
|
|
+ $data['open_people'] = request('open_people',0);
|
|
|
+ $data['partake_people'] = request('partake_people',0);
|
|
|
+ $data['exceed_people'] = request('exceed_people',0);
|
|
|
+ $data['automatic'] = request('automatic',0);
|
|
|
+ $data['virtually'] = request('virtually',0);
|
|
|
+ // 核对产品
|
|
|
+ $product_res = $Model::query()->where([['status','=', 1],['product_id','=', $data['product_id']],['end_time','>=', time()]])->first();
|
|
|
+ // 提示
|
|
|
+ if ($product_res) return json_send(['code'=>'error','msg'=>'该产品正在参加拼团活动']);
|
|
|
+ // 写入数据表
|
|
|
+ $result = $Model->add($data);
|
|
|
+ // 如果操作失败
|
|
|
+ if( !$result ) return json_send(['code'=>'error','msg'=>'复制失败']);
|
|
|
+ //商户开团
|
|
|
+ if ($data['automatic'] == 1 ) {
|
|
|
+ // 开团信息
|
|
|
+ $regimentData = [
|
|
|
+ 'custom_uid' => 0,
|
|
|
+ 'active_id' => $id,
|
|
|
+ 'product_id' => $data['product_id'],
|
|
|
+ 'status' => 1,
|
|
|
+ 'start_time' => $data['start_time'],
|
|
|
+ 'end_time' => $data['start_time'] + $data['expiration']*60*60,
|
|
|
+ 'update_time' => time(),
|
|
|
+ 'insert_time' => time(),
|
|
|
+ ];
|
|
|
+ // 开团
|
|
|
+ $regimentRes = Regiment::query()->insert($regimentData);
|
|
|
+ // 开团结果
|
|
|
+ if (!$regimentRes) 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()]]);
|
|
|
+ // 记录行为
|
|
|
+ $this->addAdminHistory(admin('uid'),$Model->getTable(),$id,2,$oldData,$data);
|
|
|
+ // 告知结果
|
|
|
+ return json_send(['code'=>'success','msg'=>'复制成功','action'=>'edit']);
|
|
|
}
|
|
|
- return json_send(['code'=>'success','msg'=>'复制成功','path'=>'']);
|
|
|
+ // 错误告知
|
|
|
+ if( !$oldData ) return $this->error('查无数据');
|
|
|
+ // 返回结果
|
|
|
+ $oldData['product_code'] = $Product->idToCode($oldData['product_id']);
|
|
|
+ $this->assign('oldData',$oldData);
|
|
|
+ $this->assign('crumbs','修改');
|
|
|
+ // 加载模板
|
|
|
+ return $this->fetch();
|
|
|
}
|
|
|
}
|