|
|
@ -11,8 +11,11 @@ |
|
|
|
|
|
|
|
|
namespace addon\zhjw\app\adminapi\controller\sales; |
|
|
namespace addon\zhjw\app\adminapi\controller\sales; |
|
|
|
|
|
|
|
|
|
|
|
use app\model\member\Member; |
|
|
|
|
|
use app\service\admin\member\MemberService; |
|
|
use core\base\BaseAdminController; |
|
|
use core\base\BaseAdminController; |
|
|
use addon\zhjw\app\service\admin\sales\SalesService; |
|
|
use addon\zhjw\app\service\admin\sales\SalesService; |
|
|
|
|
|
use think\facade\Db; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
@ -26,7 +29,8 @@ class Sales extends BaseAdminController |
|
|
* 获取销售管理列表 |
|
|
* 获取销售管理列表 |
|
|
* @return \think\Response |
|
|
* @return \think\Response |
|
|
*/ |
|
|
*/ |
|
|
public function lists(){ |
|
|
public function lists() |
|
|
|
|
|
{ |
|
|
$data = $this->request->params([ |
|
|
$data = $this->request->params([ |
|
|
["student_phone", ""], |
|
|
["student_phone", ""], |
|
|
["student_name", ""], |
|
|
["student_name", ""], |
|
|
@ -55,7 +59,8 @@ class Sales extends BaseAdminController |
|
|
* @param int $id |
|
|
* @param int $id |
|
|
* @return \think\Response |
|
|
* @return \think\Response |
|
|
*/ |
|
|
*/ |
|
|
public function info(int $id){ |
|
|
public function info(int $id) |
|
|
|
|
|
{ |
|
|
return success((new SalesService())->getInfo($id)); |
|
|
return success((new SalesService())->getInfo($id)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -63,7 +68,8 @@ class Sales extends BaseAdminController |
|
|
* 添加销售管理 |
|
|
* 添加销售管理 |
|
|
* @return \think\Response |
|
|
* @return \think\Response |
|
|
*/ |
|
|
*/ |
|
|
public function add(){ |
|
|
public function add() |
|
|
|
|
|
{ |
|
|
$data = $this->request->params([ |
|
|
$data = $this->request->params([ |
|
|
["student_phone", ""], |
|
|
["student_phone", ""], |
|
|
["student_name", ""], |
|
|
["student_name", ""], |
|
|
@ -82,6 +88,7 @@ class Sales extends BaseAdminController |
|
|
["district_id", 0], |
|
|
["district_id", 0], |
|
|
["community_name", ""], |
|
|
["community_name", ""], |
|
|
["customer_tags", []], |
|
|
["customer_tags", []], |
|
|
|
|
|
["full_address", ""], |
|
|
|
|
|
|
|
|
]); |
|
|
]); |
|
|
|
|
|
|
|
|
@ -90,7 +97,46 @@ class Sales extends BaseAdminController |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$this->validate($data, 'addon\zhjw\app\validate\sales\Sales.add'); |
|
|
$this->validate($data, 'addon\zhjw\app\validate\sales\Sales.add'); |
|
|
|
|
|
|
|
|
|
|
|
//查询用户是否注册,注册了提示报错,没注册直接注册账号 |
|
|
|
|
|
$is_member_id = Member::where('username',$data['student_phone'])->value('member_id'); |
|
|
|
|
|
if ($is_member_id){ |
|
|
|
|
|
return fail('手机号已注册'); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//开启事务 |
|
|
|
|
|
Db::startTrans(); |
|
|
|
|
|
try { |
|
|
$id = (new SalesService())->add($data); |
|
|
$id = (new SalesService())->add($data); |
|
|
|
|
|
$member_data = [ |
|
|
|
|
|
'nickname'=> $data['student_name'], |
|
|
|
|
|
'mobile'=> $data['student_phone'], |
|
|
|
|
|
'member_no'=> '', |
|
|
|
|
|
'init_member_no'=> '', |
|
|
|
|
|
'password' => substr($data['student_phone'], -4), // 截取手机号最后四位作为密码 |
|
|
|
|
|
'headimg'=> '', |
|
|
|
|
|
'member_label'=> [],//会员标签 |
|
|
|
|
|
'sex'=> $data['sex'], |
|
|
|
|
|
'birthday'=> '',//出生日期 |
|
|
|
|
|
]; |
|
|
|
|
|
$member_id = (new MemberService())->add($member_data); |
|
|
|
|
|
if (!$id || !$member_id){ |
|
|
|
|
|
Db::rollback(); |
|
|
|
|
|
return fail('操作失败'); |
|
|
|
|
|
} |
|
|
|
|
|
(new SalesService())->edit($id, ['user_id'=>$member_id]); |
|
|
|
|
|
|
|
|
|
|
|
Db::commit(); |
|
|
|
|
|
}catch (\Exception $exception){ |
|
|
|
|
|
Db::rollback(); |
|
|
|
|
|
if ($exception->getMessage() == 'MEMBER_IS_EXIST'){ |
|
|
|
|
|
return fail('账号已存在'); |
|
|
|
|
|
} |
|
|
|
|
|
return fail('操作失败'); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return success('ADD_SUCCESS', ['id' => $id]); |
|
|
return success('ADD_SUCCESS', ['id' => $id]); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -99,7 +145,8 @@ class Sales extends BaseAdminController |
|
|
* @param $id 销售管理id |
|
|
* @param $id 销售管理id |
|
|
* @return \think\Response |
|
|
* @return \think\Response |
|
|
*/ |
|
|
*/ |
|
|
public function edit(int $id){ |
|
|
public function edit(int $id) |
|
|
|
|
|
{ |
|
|
$data = $this->request->params([ |
|
|
$data = $this->request->params([ |
|
|
["student_phone", ""], |
|
|
["student_phone", ""], |
|
|
["student_name", ""], |
|
|
["student_name", ""], |
|
|
@ -118,7 +165,7 @@ class Sales extends BaseAdminController |
|
|
["district_id", 0], |
|
|
["district_id", 0], |
|
|
["community_name", ""], |
|
|
["community_name", ""], |
|
|
["customer_tags", []], |
|
|
["customer_tags", []], |
|
|
|
|
|
["full_address", ""], |
|
|
]); |
|
|
]); |
|
|
|
|
|
|
|
|
if (!empty($data['customer_tags'])) { |
|
|
if (!empty($data['customer_tags'])) { |
|
|
@ -126,7 +173,43 @@ class Sales extends BaseAdminController |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$this->validate($data, 'addon\zhjw\app\validate\sales\Sales.edit'); |
|
|
$this->validate($data, 'addon\zhjw\app\validate\sales\Sales.edit'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//查询新手机号是否存在,存在提示报错信息 |
|
|
|
|
|
//修改用户手机号 |
|
|
|
|
|
//查询用户是否注册,注册了提示报错,没注册直接注册账号 |
|
|
|
|
|
$info = (new SalesService())->getInfo($id); |
|
|
|
|
|
if($data['student_phone'] != $info['student_phone']){ |
|
|
|
|
|
$is_member_id = Member::where('username',$data['student_phone'])->value('member_id'); |
|
|
|
|
|
if ($is_member_id){ |
|
|
|
|
|
return fail('手机号已注册'); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//开启事务 |
|
|
|
|
|
Db::startTrans(); |
|
|
|
|
|
try { |
|
|
(new SalesService())->edit($id, $data); |
|
|
(new SalesService())->edit($id, $data); |
|
|
|
|
|
|
|
|
|
|
|
$member_data = [ |
|
|
|
|
|
'username'=> $data['student_phone'], |
|
|
|
|
|
'mobile'=> $data['student_phone'], |
|
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
if($data['student_phone'] != $info['student_phone']){ |
|
|
|
|
|
$member_data['password'] = substr($data['student_phone'], -4); // 截取手机号最后四位作为密码 |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$member_id = (new MemberService())->edit($info['user_id'],$member_data); |
|
|
|
|
|
(new SalesService())->edit($id, ['user_id'=>$member_id]); |
|
|
|
|
|
|
|
|
|
|
|
Db::commit(); |
|
|
|
|
|
}catch (\Exception $exception){ |
|
|
|
|
|
Db::rollback(); |
|
|
|
|
|
return fail('操作失败'); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
return success('EDIT_SUCCESS'); |
|
|
return success('EDIT_SUCCESS'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -135,17 +218,20 @@ class Sales extends BaseAdminController |
|
|
* @param $id 销售管理id |
|
|
* @param $id 销售管理id |
|
|
* @return \think\Response |
|
|
* @return \think\Response |
|
|
*/ |
|
|
*/ |
|
|
public function del(int $id){ |
|
|
public function del(int $id) |
|
|
|
|
|
{ |
|
|
(new SalesService())->del($id); |
|
|
(new SalesService())->del($id); |
|
|
return success('DELETE_SUCCESS'); |
|
|
return success('DELETE_SUCCESS'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function getStaffAll(){ |
|
|
public function getStaffAll() |
|
|
|
|
|
{ |
|
|
return success((new SalesService())->getStaffAll()); |
|
|
return success((new SalesService())->getStaffAll()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function getSysAreaAll(){ |
|
|
public function getSysAreaAll() |
|
|
|
|
|
{ |
|
|
return success((new SalesService())->getSysAreaAll()); |
|
|
return success((new SalesService())->getSysAreaAll()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|