| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713 |
- <?php
- /**
- * @package 商户端
- * @Author: ljj
- * @Date: 2021/1/5
- */
- namespace app\controller\api\merchant;
- use think\App;
- use crmeb\basic\BaseController;
- use app\common\repositories\user\UserRelationRepository;
- use app\common\repositories\store\order\StoreOrderRepository;
- use app\common\repositories\user\UserVisitRepository;
- use app\common\repositories\merchant\MerchantRepository as repository;
- use think\exception\ValidateException;
- use think\facade\Db;
- class Merchant extends BaseController
- {
- protected $repository;
- protected $userInfo;
- /**
- * ProductCategory constructor.
- * @param App $app
- * @param repository $repository
- */
- public function __construct(App $app, repository $repository)
- {
- parent::__construct($app);
- $this->repository = $repository;
- $this->userInfo =$this->request->isLogin() ? $this->request->userInfo():null;
- }
- /**
- * 商户信息 聚合码
- * @Author:ljj
- * @Date: 2021/1/5
- * @return mixed
- * @param mer_id 商户id
- */
- public function index()
- {
- $data=$this->request->params(['mer_id']);
- $uid=$this->request->uid();
- $res=$this->repository->index($uid,$data);
- if($res){
- return app('json')->success($res);
- }else{
- return app('json')->fail($res);
- }
- }
- /**
- * 首页/统计
- * @Author:ljj
- * @Date: 2021/1/5
- * @return mixed
- * @param null $merId 商户id
- */
- public function report_form()
- {
- $uid=$this->request->uid();
- $data=$this->request->params(['mer_id','day']);
- $merId=$data["mer_id"];
- $day=$data["day"];
- $res = $this->repository->report_form($uid,$merId,$day);
- if($res){
- return app('json')->success($res);
- }else{
- return app('json')->fail($res);
- }
- }
- public function mainGroup($date, $merId)
- {
- $userVisitRepository = app()->make(UserVisitRepository::class);
- $repository = app()->make(StoreOrderRepository::class);
- $relationRepository = app()->make(UserRelationRepository::class);
- $orderNum = $repository->dayOrderNum($date, $merId);
- $payPrice = $repository->dayOrderPrice($date, $merId);
- $payUser = $repository->dayOrderUserNum($date, $merId);
- $visitNum = $userVisitRepository->dateVisitUserNum($date, $merId);
- // $likeStore = $relationRepository->dayLikeStore($date, $merId);
- return compact('orderNum', 'payPrice', 'payUser', 'visitNum');
- }
- /**
- * 返金设置
- * @Author:ljj
- * @Date: 2021/1/5
- * @return mixed
- * @param null $merId 商户id
- */
- public function set_rebate(){
- $uid=$this->request->uid();
- $data=$this->request->params(["mer_id","value"]);
- $res=$this->repository->set_rebate($uid,$data);
- if($res["code"]==1){
- return app('json')->success("设置成功");
- }else{
- return app('json')->fail("设置失败:".$res["msg"]);
- }
- }
- /**
- * 最新数据
- * @Author:ljj
- * @Date: 2021/1/5
- * @return mixed
- * @param null $merId 商户id
- */
- public function newest_data(){
- $uid=$this->request->uid();
- $data=$this->request->params(["mer_id","page","limit"]);
- $res=$this->repository->newest_data($uid,$data);
- if($res){
- return app('json')->success($res);
- }else{
- return app('json')->fail("暂无数据");
- }
- }
- /**
- * 分店列表
- * @Author:ljj
- * @Date: 2021/1/6
- * @return mixed
- */
- public function branch_list(){
- $uid=$this->request->uid();
- $data=$this->request->params(["mer_id"]);
- $res=$this->repository->branch_list($uid,$data);
- if($res){
- return app('json')->success($res);
- }else{
- return app('json')->fail("暂无数据");
- }
- }
- /**
- * 优惠列表
- * @Author:ljj
- * @Date: 2021/1/6
- * @return mixed
- */
- public function recharge_list(){
- $uid=$this->request->uid();
- $data=$this->request->params(["mer_id"]);
- $res=$this->repository->recharge_list($uid,$data);
- if($res){
- return app('json')->success($res);
- }else{
- return app('json')->fail("设置失败");
- }
- }
- /**
- * 添加/编辑优惠
- * @Author:ljj
- * @Date: 2021/1/6
- * @return mixed
- */
- public function add_recharge(){
- $uid=$this->request->uid();
- $data=$this->request->params(["mer_id","price","give","statime","endtime","title","id"]);
- $res=$this->repository->add_recharge($uid,$data);
- if($res){
- return app('json')->success("ok");
- }else{
- return app('json')->fail("err");
- }
- }
- /**
- * 编辑优惠返回一条数据
- * @Author:ljj
- * @Date: 2021/1/6
- * @return mixed
- */
- public function get_recharge_on(){
- $uid=$this->request->uid();
- $data=$this->request->params(["mer_id","id"]);
- $res=$this->repository->get_recharge_on($uid,$data);
- if($res){
- return app('json')->success($res);
- }else{
- return app('json')->fail("暂无数据");
- }
- }
- /**
- * 删除一条数据
- * @Author:ljj
- * @Date: 2021/1/6
- * @return mixed
- */
- public function del_recharge(){
- $uid=$this->request->uid();
- $data=$this->request->params(["mer_id","id"]);
- $res=$this->repository->del_recharge($uid,$data);
- if($res){
- return app('json')->success("删除成功");
- }else{
- return app('json')->fail("删除失败");
- }
- }
- /**
- * 员工管理:添加员工
- * @Author:ljj
- * @Date: 2021/1/7
- * @return mixed
- */
- public function add_staff(){
- $uid=$this->request->uid();
- $data=$this->request->params(["mer_id","name","department","phone","password"]);
- $res=$this->repository->add_staff($uid,$data);
- if($res){
- return app('json')->success("添加成功");
- }else{
- return app('json')->fail("添加失败,员工已存在");
- }
- }
- /**
- * 员工管理:员工列表
- * @Author:ljj
- * @Date: 2021/1/7
- * @return mixed
- */
- public function staff_list(){
- $uid=$this->request->uid();
- $data=$this->request->params(["mer_id"]);
- $res=$this->repository->staff_list($uid,$data);
- if($res){
- return app('json')->success($res);
- }else{
- return app('json')->fail("暂无数据");
- }
- }
- /**
- * 员工管理:员工详情
- * @Author:ljj
- * @Date: 2021/1/7
- * @return mixed
- */
- public function get_staff_one(){
- $uid=$this->request->uid();
- $data=$this->request->params(["mer_id","id"]);
- $res=$this->repository->get_staff_one($uid,$data);
- if($res){
- return app('json')->success($res);
- }else{
- return app('json')->fail("暂无数据");
- }
- }
- /**
- * 员工管理:员工编辑
- * @Author:ljj
- * @Date: 2021/1/7
- * @return mixed
- */
- public function edit_staff(){
- $uid=$this->request->uid();
- $data=$this->request->params(["mer_id","id","name","department"]);
- $res=$this->repository->edit_staff($uid,$data);
- if($res){
- return app('json')->success('修改成功');
- }else{
- return app('json')->fail("无修改");
- }
- }
- /**
- * 员工管理:删除员工
- * @Author:ljj
- * @Date: 2021/1/7
- * @return mixed
- */
- public function del_staff(){
- $uid=$this->request->uid();
- $data=$this->request->params(["mer_id","id"]);
- $res=$this->repository->del_staff($uid,$data);
- if($res){
- return app('json')->success('删除成功');
- }else{
- return app('json')->fail("删除失败");
- }
- }
- /**
- * 部门管理:添加部门
- * @Author:ljj
- * @Date: 2021/1/8
- * @return mixed
- */
- public function add_branch(){
- $uid=$this->request->uid();
- $data=$this->request->params(["mer_id","branch","jurisdiction"]);
- $res=$this->repository->add_branch($uid,$data);
- if($res){
- return app('json')->success("添加成功");
- }else{
- return app('json')->fail("添加失败:部门已存在");
- }
- }
- /**
- * 部门管理:获取部门列表
- * @Author:ljj
- * @Date: 2021/1/8
- * @return mixed
- */
- public function get_branch(){
- $uid=$this->request->uid();
- $data=$this->request->params(["mer_id"]);
- $res=$this->repository->get_branch($uid,$data);
- if($res){
- return app('json')->success($res);
- }else{
- return app('json')->fail("暂无数据");
- }
- }
- /**
- * 部门管理:删除部门
- * @Author:ljj
- * @Date: 2021/1/8
- * @return mixed
- */
- public function del_branch(){
- $uid=$this->request->uid();
- $data=$this->request->params(["mer_id","id"]);
- $res=$this->repository->del_branch($uid,$data);
- if($res){
- return app('json')->success("删除成功");
- }else{
- return app('json')->fail("删除失败");
- }
- }
- /**
- * 部门管理:权限列表
- * @Author:ljj
- * @Date: 2021/1/8
- * @return mixed
- */
- public function branch_quanxian(){
- $uid=$this->request->uid();
- // $data=$this->request->params(["mer_id","id"]);
- $res=$this->repository->branch_quanxian($uid);
- if($res){
- return app('json')->success($res);
- }else{
- return app('json')->fail("暂无数据");
- }
- }
- /**
- * 锁定奖励:奖励统计
- * @Author:ljj
- * @Date: 2021/1/8
- * @return mixed
- */
- public function lock_count(){
- $uid=$this->request->uid();
- $data=$this->request->params(["mer_id"]);
- $res=$this->repository->lock_count($uid,$data);
- if($res){
- return app('json')->success($res);
- }else{
- return app('json')->fail("暂无数据");
- }
- }
- /**
- * 余额奖励:奖励统计
- * @Author:ljj
- * @Date: 2021/1/8
- * @return mixed
- */
- public function count_price(){
- $uid=$this->request->uid();
- $data=$this->request->params(["mer_id"]);
- $res=$this->repository->count_price($uid,$data);
- if($res){
- return app('json')->success($res);
- }else{
- return app('json')->fail("暂无数据");
- }
- }
- /**
- * 消息通知
- * @Author:ljj
- * @Date: 2021/1/8
- * @return mixed
- */
- public function msg_notice(){
- $uid=$this->request->uid();
- $data=$this->request->params(["mer_id","page","limit"]);
- $res=$this->repository->msg_notice($uid,$data);
- if($res){
- return app('json')->success($res);
- }else{
- return app('json')->fail("暂无数据");
- }
- }
- /**
- * 删除消息
- * @Author:ljj
- * @Date: 2021/1/8
- * @return mixed
- */
- public function del_notice(){
- $uid=$this->request->uid();
- $data=$this->request->params(["mer_id","ids"]);
- $res=$this->repository->del_notice($uid,$data);
- if($res){
- return app('json')->success("删除成功");
- }else{
- return app('json')->fail("删除失败");
- }
- }
- /**
- * 推荐人管理
- * @Author:ljj
- * @Date: 2021/1/8
- * @return mixed
- */
- public function tuijian(){
- $uid=$this->request->uid();
- $data=$this->request->params(["mer_id"]);
- $res=$this->repository->tuijian($uid,$data);
- if($res){
- return app('json')->success($res);
- }else{
- return app('json')->fail("暂无数据");
- }
- }
- /**
- * 折线图
- * @Author:ljj
- * @Date: 2021/1/18
- * @return mixed
- * @param null $merId 商户id
- */
- public function statistical_chart()
- {
- $uid=$this->request->uid();
- $data=$this->request->params(['mer_id','day']);
- $merId=$data["mer_id"];
- $res = $this->repository->statistical_chart($uid,$merId);
- if($res){
- return app('json')->success($res);
- }else{
- return app('json')->fail($res);
- }
- }
- /**
- * 店铺信息
- * 2021/1/30
- * @mer_id 商户
- * @return mixed
- */
- public function get_mer_info(){
- $data=$this->request->params(['mer_id']);
- $merId=$data["mer_id"];
- if(strpos($merId,'_') !== false){
- $mer = explode("_",$merId);
- $merId=$mer[0];
- }
- $res = $this->repository->get_mer_info($merId);
- if (isset($mer)){
- $res['mer_id'] = $mer[0]."_".$mer[1];
- }
- if($res){
- return app('json')->success($res);
- }else{
- return app('json')->fail($res);
- }
- }
- /**
- * 会员管理:会员列表
- * @Author:ljj
- * @Date: 2021/1/7
- * @return mixed
- */
- public function mer_user(){
- $uid=$this->request->uid();
- $data=$this->request->params(["mer_id","search"]);
- $res=$this->repository->new_mer_user($uid,$data);
- if($res){
- return app('json')->success($res);
- }else{
- return app('json')->fail("暂无数据");
- }
- }
- /**
- * 会员管理:会员详情
- * @Author:ljj
- * @Date: 2021/1/7
- * @return mixed
- */
- public function mer_user_info(){
- $uid=$this->request->uid();
- $data=$this->request->params(["uid","mer_id"]);
- $res=$this->repository->merchant_user_log($uid,$data);
- if($res){
- return app('json')->success($res);
- }else{
- return app('json')->fail("暂无数据");
- }
- }
- /**
- * 添加商户会员
- */
- public function add_user(){
- $uid=$this->request->uid();
- $data=$this->request->params(["mer_id","name","phone","birthday","sex"]);
- $res=$this->repository->new_add_mer_user($uid,$data);
- if($res){
- return app('json')->success("添加成功");
- }else{
- return app('json')->fail("添加失败,用户已存在");
- }
- }
- /**
- * 用户消费
- * @return mixed
- */
- public function reduce_money(){
- $uid=$this->request->uid();
- $data=$this->request->params(["mer_id","id","money"]);
- $res=$this->repository->reduce_money($uid,$data);
- if($res){
- return app('json')->success("消费成功");
- }else{
- return app('json')->fail("消费失败余额不足");
- }
- }
- /**
- * 绑定音响
- * @Author:lin
- * @Date: 2021/3/29
- */
- public function bind_yx(){
- $uid=$this->request->uid();
- $data=$this->request->params(['mer_id','sn']);
- $data['uid'] = $uid;
- $res = $this -> repository -> set_yx($data);
- if($res["code"]==1){
- return app('json')->success("绑定成功");
- }else{
- return app('json')->fail("绑定失败:".$res["msg"]);
- }
- }
- /**
- * 音响试播
- * @Author:lin
- * @Date: 2021/3/30
- */
- public function check_yx(){
- $data=$this->request->params(['mer_id']);
- $redis = new \Redis();
- $redis -> pconnect('10.28.5.50','6380');
- $redis -> auth('zKiDUex5YC');
- $redis -> select(1);
- //商户sn编号
- $sn = Db::name('merchant_yx')
- -> where('mer_id',$data['mer_id'])
- -> where('status',1)
- -> find();
- $task = [
- 'sn' => $sn['sn'],
- 'data'=>'您的音响设备编号是'.implode(',',str_split($sn['sn'])),
- ];
- $redis->publish('yx', serialize($task));
- }
- /**
- * 音响调试
- * @Author:lin
- * @Date: 2023/3/3
- */
- public function check_yx_info(){
- $data=$this->request->params(['mer_id']);
- $redis = new \Redis();
- $redis -> pconnect('10.28.5.50','6380');
- $redis -> auth('zKiDUex5YC');
- $redis -> select(1);
- //商户sn编号
- $sn = Db::name('merchant_yx')
- -> where('mer_id',$data['mer_id'])
- -> where('status',1)
- -> find();
- $broadcast = '用户到店消费982.88元';
- $task = [
- 'sn' => $sn['sn'],
- 'data' => $broadcast,
- ];
- $redis->publish('yx', serialize($task));
- }
- /**
- * 开启消费分
- * @Author:lin
- * @Date: 2022/7/19
- */
- public function consumption_score(){
- // 启动事务
- Db::startTrans();
- try {
- $uid=$this->request->uid();
- $data=$this->request->params(['mer_id']);
- $u = Db::name('merchant') -> where('uid',$uid) -> where('mer_id',$data['mer_id']) -> field('consumption_score') -> find();
- if(!$u){
- throw new ValidateException('商户不匹配');
- }
- if($u['consumption_score'] == 1){
- throw new ValidateException('已开启');
- }
- Db::name('merchant') -> where('uid',$uid) -> where('mer_id',$data['mer_id']) -> update(['consumption_score'=>1]);
- $where=[];
- $where["mer_id"]=$data["mer_id"];
- $where["config_key"]="base_commission";
- $data["value"] = 2;
- $merbili=Db::name("system_config_value")
- ->where($where)->find();
- $base_commission = systemConfig('extension_one_rate');
- if($base_commission>0&&$base_commission>$data["value"]){
- throw new ValidateException('商户返利比例低于系统比例');
- }
- if ($merbili){
- if($merbili['value'] < 2){
- $mer=Db::name("system_config_value")
- ->where($where)
- ->update(
- [
- "value"=>$data["value"]
- ]
- );
- }
- }else{
- $mer=Db::name("system_config_value")
- ->insert(
- [
- "config_key"=>"base_commission",
- "mer_id"=>$data["mer_id"],
- "value"=>$data["value"]
- ]
- );
- }
- // 提交事务
- Db::commit();
- return app('json')->success("开启成功");
- } catch (\Exception $e) {
- // 回滚事务
- Db::rollback();
- }
- }
- public function get_consumption_score(){
- $uid=$this->request->uid();
- $all = Db::name('merchant_consumption_score_log')
- -> where('uid',$uid)
- -> select();
- //已结算,预估,已释放
- $a = $b = $c = 0;
- foreach ($all as $key => $value){
- if($value['pm'] == 1 && ($value['status'] == 1 || $value['status'] == 3) && $value['order_id'] > 0){
- $a += $value['consumption_score'];
- }
- if($value['pm'] == 1 && $value['status'] == 0 && $value['order_id'] > 0){
- $b += $value['consumption_score'];
- }
- if ($value['pm'] == 2){
- $c += $value['consumption_score'];
- }
- }
- $data['settled'] = $a;
- $data['predict'] = $b;
- $data['release'] = $c;
- return app('json')->success($data);
- }
- //消费分
- public function get_consumption_score_list(){
- $uid=$this->request->uid();
- [$page,$limit] = $this->getPage();
- $count = Db::name('merchant_consumption_score_log')
- -> where('uid',$uid)
- -> count();
- $list = Db::name('merchant_consumption_score_log')
- -> where('uid',$uid)
- -> page($page,$limit)
- -> select()
- -> each(function ($item){
- $item['add_time'] = date('Y-m-d H:i:s',$item['add_time']);
- $item['update_time'] = date('Y-m-d H:i:s',$item['update_time']);
- return $item;
- });
- return app('json')->success(['list'=>$list,'count'=>$count]);
- }
- }
|