Merchant.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713
  1. <?php
  2. /**
  3. * @package 商户端
  4. * @Author: ljj
  5. * @Date: 2021/1/5
  6. */
  7. namespace app\controller\api\merchant;
  8. use think\App;
  9. use crmeb\basic\BaseController;
  10. use app\common\repositories\user\UserRelationRepository;
  11. use app\common\repositories\store\order\StoreOrderRepository;
  12. use app\common\repositories\user\UserVisitRepository;
  13. use app\common\repositories\merchant\MerchantRepository as repository;
  14. use think\exception\ValidateException;
  15. use think\facade\Db;
  16. class Merchant extends BaseController
  17. {
  18. protected $repository;
  19. protected $userInfo;
  20. /**
  21. * ProductCategory constructor.
  22. * @param App $app
  23. * @param repository $repository
  24. */
  25. public function __construct(App $app, repository $repository)
  26. {
  27. parent::__construct($app);
  28. $this->repository = $repository;
  29. $this->userInfo =$this->request->isLogin() ? $this->request->userInfo():null;
  30. }
  31. /**
  32. * 商户信息 聚合码
  33. * @Author:ljj
  34. * @Date: 2021/1/5
  35. * @return mixed
  36. * @param mer_id 商户id
  37. */
  38. public function index()
  39. {
  40. $data=$this->request->params(['mer_id']);
  41. $uid=$this->request->uid();
  42. $res=$this->repository->index($uid,$data);
  43. if($res){
  44. return app('json')->success($res);
  45. }else{
  46. return app('json')->fail($res);
  47. }
  48. }
  49. /**
  50. * 首页/统计
  51. * @Author:ljj
  52. * @Date: 2021/1/5
  53. * @return mixed
  54. * @param null $merId 商户id
  55. */
  56. public function report_form()
  57. {
  58. $uid=$this->request->uid();
  59. $data=$this->request->params(['mer_id','day']);
  60. $merId=$data["mer_id"];
  61. $day=$data["day"];
  62. $res = $this->repository->report_form($uid,$merId,$day);
  63. if($res){
  64. return app('json')->success($res);
  65. }else{
  66. return app('json')->fail($res);
  67. }
  68. }
  69. public function mainGroup($date, $merId)
  70. {
  71. $userVisitRepository = app()->make(UserVisitRepository::class);
  72. $repository = app()->make(StoreOrderRepository::class);
  73. $relationRepository = app()->make(UserRelationRepository::class);
  74. $orderNum = $repository->dayOrderNum($date, $merId);
  75. $payPrice = $repository->dayOrderPrice($date, $merId);
  76. $payUser = $repository->dayOrderUserNum($date, $merId);
  77. $visitNum = $userVisitRepository->dateVisitUserNum($date, $merId);
  78. // $likeStore = $relationRepository->dayLikeStore($date, $merId);
  79. return compact('orderNum', 'payPrice', 'payUser', 'visitNum');
  80. }
  81. /**
  82. * 返金设置
  83. * @Author:ljj
  84. * @Date: 2021/1/5
  85. * @return mixed
  86. * @param null $merId 商户id
  87. */
  88. public function set_rebate(){
  89. $uid=$this->request->uid();
  90. $data=$this->request->params(["mer_id","value"]);
  91. $res=$this->repository->set_rebate($uid,$data);
  92. if($res["code"]==1){
  93. return app('json')->success("设置成功");
  94. }else{
  95. return app('json')->fail("设置失败:".$res["msg"]);
  96. }
  97. }
  98. /**
  99. * 最新数据
  100. * @Author:ljj
  101. * @Date: 2021/1/5
  102. * @return mixed
  103. * @param null $merId 商户id
  104. */
  105. public function newest_data(){
  106. $uid=$this->request->uid();
  107. $data=$this->request->params(["mer_id","page","limit"]);
  108. $res=$this->repository->newest_data($uid,$data);
  109. if($res){
  110. return app('json')->success($res);
  111. }else{
  112. return app('json')->fail("暂无数据");
  113. }
  114. }
  115. /**
  116. * 分店列表
  117. * @Author:ljj
  118. * @Date: 2021/1/6
  119. * @return mixed
  120. */
  121. public function branch_list(){
  122. $uid=$this->request->uid();
  123. $data=$this->request->params(["mer_id"]);
  124. $res=$this->repository->branch_list($uid,$data);
  125. if($res){
  126. return app('json')->success($res);
  127. }else{
  128. return app('json')->fail("暂无数据");
  129. }
  130. }
  131. /**
  132. * 优惠列表
  133. * @Author:ljj
  134. * @Date: 2021/1/6
  135. * @return mixed
  136. */
  137. public function recharge_list(){
  138. $uid=$this->request->uid();
  139. $data=$this->request->params(["mer_id"]);
  140. $res=$this->repository->recharge_list($uid,$data);
  141. if($res){
  142. return app('json')->success($res);
  143. }else{
  144. return app('json')->fail("设置失败");
  145. }
  146. }
  147. /**
  148. * 添加/编辑优惠
  149. * @Author:ljj
  150. * @Date: 2021/1/6
  151. * @return mixed
  152. */
  153. public function add_recharge(){
  154. $uid=$this->request->uid();
  155. $data=$this->request->params(["mer_id","price","give","statime","endtime","title","id"]);
  156. $res=$this->repository->add_recharge($uid,$data);
  157. if($res){
  158. return app('json')->success("ok");
  159. }else{
  160. return app('json')->fail("err");
  161. }
  162. }
  163. /**
  164. * 编辑优惠返回一条数据
  165. * @Author:ljj
  166. * @Date: 2021/1/6
  167. * @return mixed
  168. */
  169. public function get_recharge_on(){
  170. $uid=$this->request->uid();
  171. $data=$this->request->params(["mer_id","id"]);
  172. $res=$this->repository->get_recharge_on($uid,$data);
  173. if($res){
  174. return app('json')->success($res);
  175. }else{
  176. return app('json')->fail("暂无数据");
  177. }
  178. }
  179. /**
  180. * 删除一条数据
  181. * @Author:ljj
  182. * @Date: 2021/1/6
  183. * @return mixed
  184. */
  185. public function del_recharge(){
  186. $uid=$this->request->uid();
  187. $data=$this->request->params(["mer_id","id"]);
  188. $res=$this->repository->del_recharge($uid,$data);
  189. if($res){
  190. return app('json')->success("删除成功");
  191. }else{
  192. return app('json')->fail("删除失败");
  193. }
  194. }
  195. /**
  196. * 员工管理:添加员工
  197. * @Author:ljj
  198. * @Date: 2021/1/7
  199. * @return mixed
  200. */
  201. public function add_staff(){
  202. $uid=$this->request->uid();
  203. $data=$this->request->params(["mer_id","name","department","phone","password"]);
  204. $res=$this->repository->add_staff($uid,$data);
  205. if($res){
  206. return app('json')->success("添加成功");
  207. }else{
  208. return app('json')->fail("添加失败,员工已存在");
  209. }
  210. }
  211. /**
  212. * 员工管理:员工列表
  213. * @Author:ljj
  214. * @Date: 2021/1/7
  215. * @return mixed
  216. */
  217. public function staff_list(){
  218. $uid=$this->request->uid();
  219. $data=$this->request->params(["mer_id"]);
  220. $res=$this->repository->staff_list($uid,$data);
  221. if($res){
  222. return app('json')->success($res);
  223. }else{
  224. return app('json')->fail("暂无数据");
  225. }
  226. }
  227. /**
  228. * 员工管理:员工详情
  229. * @Author:ljj
  230. * @Date: 2021/1/7
  231. * @return mixed
  232. */
  233. public function get_staff_one(){
  234. $uid=$this->request->uid();
  235. $data=$this->request->params(["mer_id","id"]);
  236. $res=$this->repository->get_staff_one($uid,$data);
  237. if($res){
  238. return app('json')->success($res);
  239. }else{
  240. return app('json')->fail("暂无数据");
  241. }
  242. }
  243. /**
  244. * 员工管理:员工编辑
  245. * @Author:ljj
  246. * @Date: 2021/1/7
  247. * @return mixed
  248. */
  249. public function edit_staff(){
  250. $uid=$this->request->uid();
  251. $data=$this->request->params(["mer_id","id","name","department"]);
  252. $res=$this->repository->edit_staff($uid,$data);
  253. if($res){
  254. return app('json')->success('修改成功');
  255. }else{
  256. return app('json')->fail("无修改");
  257. }
  258. }
  259. /**
  260. * 员工管理:删除员工
  261. * @Author:ljj
  262. * @Date: 2021/1/7
  263. * @return mixed
  264. */
  265. public function del_staff(){
  266. $uid=$this->request->uid();
  267. $data=$this->request->params(["mer_id","id"]);
  268. $res=$this->repository->del_staff($uid,$data);
  269. if($res){
  270. return app('json')->success('删除成功');
  271. }else{
  272. return app('json')->fail("删除失败");
  273. }
  274. }
  275. /**
  276. * 部门管理:添加部门
  277. * @Author:ljj
  278. * @Date: 2021/1/8
  279. * @return mixed
  280. */
  281. public function add_branch(){
  282. $uid=$this->request->uid();
  283. $data=$this->request->params(["mer_id","branch","jurisdiction"]);
  284. $res=$this->repository->add_branch($uid,$data);
  285. if($res){
  286. return app('json')->success("添加成功");
  287. }else{
  288. return app('json')->fail("添加失败:部门已存在");
  289. }
  290. }
  291. /**
  292. * 部门管理:获取部门列表
  293. * @Author:ljj
  294. * @Date: 2021/1/8
  295. * @return mixed
  296. */
  297. public function get_branch(){
  298. $uid=$this->request->uid();
  299. $data=$this->request->params(["mer_id"]);
  300. $res=$this->repository->get_branch($uid,$data);
  301. if($res){
  302. return app('json')->success($res);
  303. }else{
  304. return app('json')->fail("暂无数据");
  305. }
  306. }
  307. /**
  308. * 部门管理:删除部门
  309. * @Author:ljj
  310. * @Date: 2021/1/8
  311. * @return mixed
  312. */
  313. public function del_branch(){
  314. $uid=$this->request->uid();
  315. $data=$this->request->params(["mer_id","id"]);
  316. $res=$this->repository->del_branch($uid,$data);
  317. if($res){
  318. return app('json')->success("删除成功");
  319. }else{
  320. return app('json')->fail("删除失败");
  321. }
  322. }
  323. /**
  324. * 部门管理:权限列表
  325. * @Author:ljj
  326. * @Date: 2021/1/8
  327. * @return mixed
  328. */
  329. public function branch_quanxian(){
  330. $uid=$this->request->uid();
  331. // $data=$this->request->params(["mer_id","id"]);
  332. $res=$this->repository->branch_quanxian($uid);
  333. if($res){
  334. return app('json')->success($res);
  335. }else{
  336. return app('json')->fail("暂无数据");
  337. }
  338. }
  339. /**
  340. * 锁定奖励:奖励统计
  341. * @Author:ljj
  342. * @Date: 2021/1/8
  343. * @return mixed
  344. */
  345. public function lock_count(){
  346. $uid=$this->request->uid();
  347. $data=$this->request->params(["mer_id"]);
  348. $res=$this->repository->lock_count($uid,$data);
  349. if($res){
  350. return app('json')->success($res);
  351. }else{
  352. return app('json')->fail("暂无数据");
  353. }
  354. }
  355. /**
  356. * 余额奖励:奖励统计
  357. * @Author:ljj
  358. * @Date: 2021/1/8
  359. * @return mixed
  360. */
  361. public function count_price(){
  362. $uid=$this->request->uid();
  363. $data=$this->request->params(["mer_id"]);
  364. $res=$this->repository->count_price($uid,$data);
  365. if($res){
  366. return app('json')->success($res);
  367. }else{
  368. return app('json')->fail("暂无数据");
  369. }
  370. }
  371. /**
  372. * 消息通知
  373. * @Author:ljj
  374. * @Date: 2021/1/8
  375. * @return mixed
  376. */
  377. public function msg_notice(){
  378. $uid=$this->request->uid();
  379. $data=$this->request->params(["mer_id","page","limit"]);
  380. $res=$this->repository->msg_notice($uid,$data);
  381. if($res){
  382. return app('json')->success($res);
  383. }else{
  384. return app('json')->fail("暂无数据");
  385. }
  386. }
  387. /**
  388. * 删除消息
  389. * @Author:ljj
  390. * @Date: 2021/1/8
  391. * @return mixed
  392. */
  393. public function del_notice(){
  394. $uid=$this->request->uid();
  395. $data=$this->request->params(["mer_id","ids"]);
  396. $res=$this->repository->del_notice($uid,$data);
  397. if($res){
  398. return app('json')->success("删除成功");
  399. }else{
  400. return app('json')->fail("删除失败");
  401. }
  402. }
  403. /**
  404. * 推荐人管理
  405. * @Author:ljj
  406. * @Date: 2021/1/8
  407. * @return mixed
  408. */
  409. public function tuijian(){
  410. $uid=$this->request->uid();
  411. $data=$this->request->params(["mer_id"]);
  412. $res=$this->repository->tuijian($uid,$data);
  413. if($res){
  414. return app('json')->success($res);
  415. }else{
  416. return app('json')->fail("暂无数据");
  417. }
  418. }
  419. /**
  420. * 折线图
  421. * @Author:ljj
  422. * @Date: 2021/1/18
  423. * @return mixed
  424. * @param null $merId 商户id
  425. */
  426. public function statistical_chart()
  427. {
  428. $uid=$this->request->uid();
  429. $data=$this->request->params(['mer_id','day']);
  430. $merId=$data["mer_id"];
  431. $res = $this->repository->statistical_chart($uid,$merId);
  432. if($res){
  433. return app('json')->success($res);
  434. }else{
  435. return app('json')->fail($res);
  436. }
  437. }
  438. /**
  439. * 店铺信息
  440. * 2021/1/30
  441. * @mer_id 商户
  442. * @return mixed
  443. */
  444. public function get_mer_info(){
  445. $data=$this->request->params(['mer_id']);
  446. $merId=$data["mer_id"];
  447. if(strpos($merId,'_') !== false){
  448. $mer = explode("_",$merId);
  449. $merId=$mer[0];
  450. }
  451. $res = $this->repository->get_mer_info($merId);
  452. if (isset($mer)){
  453. $res['mer_id'] = $mer[0]."_".$mer[1];
  454. }
  455. if($res){
  456. return app('json')->success($res);
  457. }else{
  458. return app('json')->fail($res);
  459. }
  460. }
  461. /**
  462. * 会员管理:会员列表
  463. * @Author:ljj
  464. * @Date: 2021/1/7
  465. * @return mixed
  466. */
  467. public function mer_user(){
  468. $uid=$this->request->uid();
  469. $data=$this->request->params(["mer_id","search"]);
  470. $res=$this->repository->new_mer_user($uid,$data);
  471. if($res){
  472. return app('json')->success($res);
  473. }else{
  474. return app('json')->fail("暂无数据");
  475. }
  476. }
  477. /**
  478. * 会员管理:会员详情
  479. * @Author:ljj
  480. * @Date: 2021/1/7
  481. * @return mixed
  482. */
  483. public function mer_user_info(){
  484. $uid=$this->request->uid();
  485. $data=$this->request->params(["uid","mer_id"]);
  486. $res=$this->repository->merchant_user_log($uid,$data);
  487. if($res){
  488. return app('json')->success($res);
  489. }else{
  490. return app('json')->fail("暂无数据");
  491. }
  492. }
  493. /**
  494. * 添加商户会员
  495. */
  496. public function add_user(){
  497. $uid=$this->request->uid();
  498. $data=$this->request->params(["mer_id","name","phone","birthday","sex"]);
  499. $res=$this->repository->new_add_mer_user($uid,$data);
  500. if($res){
  501. return app('json')->success("添加成功");
  502. }else{
  503. return app('json')->fail("添加失败,用户已存在");
  504. }
  505. }
  506. /**
  507. * 用户消费
  508. * @return mixed
  509. */
  510. public function reduce_money(){
  511. $uid=$this->request->uid();
  512. $data=$this->request->params(["mer_id","id","money"]);
  513. $res=$this->repository->reduce_money($uid,$data);
  514. if($res){
  515. return app('json')->success("消费成功");
  516. }else{
  517. return app('json')->fail("消费失败余额不足");
  518. }
  519. }
  520. /**
  521. * 绑定音响
  522. * @Author:lin
  523. * @Date: 2021/3/29
  524. */
  525. public function bind_yx(){
  526. $uid=$this->request->uid();
  527. $data=$this->request->params(['mer_id','sn']);
  528. $data['uid'] = $uid;
  529. $res = $this -> repository -> set_yx($data);
  530. if($res["code"]==1){
  531. return app('json')->success("绑定成功");
  532. }else{
  533. return app('json')->fail("绑定失败:".$res["msg"]);
  534. }
  535. }
  536. /**
  537. * 音响试播
  538. * @Author:lin
  539. * @Date: 2021/3/30
  540. */
  541. public function check_yx(){
  542. $data=$this->request->params(['mer_id']);
  543. $redis = new \Redis();
  544. $redis -> pconnect('10.28.5.50','6380');
  545. $redis -> auth('zKiDUex5YC');
  546. $redis -> select(1);
  547. //商户sn编号
  548. $sn = Db::name('merchant_yx')
  549. -> where('mer_id',$data['mer_id'])
  550. -> where('status',1)
  551. -> find();
  552. $task = [
  553. 'sn' => $sn['sn'],
  554. 'data'=>'您的音响设备编号是'.implode(',',str_split($sn['sn'])),
  555. ];
  556. $redis->publish('yx', serialize($task));
  557. }
  558. /**
  559. * 音响调试
  560. * @Author:lin
  561. * @Date: 2023/3/3
  562. */
  563. public function check_yx_info(){
  564. $data=$this->request->params(['mer_id']);
  565. $redis = new \Redis();
  566. $redis -> pconnect('10.28.5.50','6380');
  567. $redis -> auth('zKiDUex5YC');
  568. $redis -> select(1);
  569. //商户sn编号
  570. $sn = Db::name('merchant_yx')
  571. -> where('mer_id',$data['mer_id'])
  572. -> where('status',1)
  573. -> find();
  574. $broadcast = '用户到店消费982.88元';
  575. $task = [
  576. 'sn' => $sn['sn'],
  577. 'data' => $broadcast,
  578. ];
  579. $redis->publish('yx', serialize($task));
  580. }
  581. /**
  582. * 开启消费分
  583. * @Author:lin
  584. * @Date: 2022/7/19
  585. */
  586. public function consumption_score(){
  587. // 启动事务
  588. Db::startTrans();
  589. try {
  590. $uid=$this->request->uid();
  591. $data=$this->request->params(['mer_id']);
  592. $u = Db::name('merchant') -> where('uid',$uid) -> where('mer_id',$data['mer_id']) -> field('consumption_score') -> find();
  593. if(!$u){
  594. throw new ValidateException('商户不匹配');
  595. }
  596. if($u['consumption_score'] == 1){
  597. throw new ValidateException('已开启');
  598. }
  599. Db::name('merchant') -> where('uid',$uid) -> where('mer_id',$data['mer_id']) -> update(['consumption_score'=>1]);
  600. $where=[];
  601. $where["mer_id"]=$data["mer_id"];
  602. $where["config_key"]="base_commission";
  603. $data["value"] = 2;
  604. $merbili=Db::name("system_config_value")
  605. ->where($where)->find();
  606. $base_commission = systemConfig('extension_one_rate');
  607. if($base_commission>0&&$base_commission>$data["value"]){
  608. throw new ValidateException('商户返利比例低于系统比例');
  609. }
  610. if ($merbili){
  611. if($merbili['value'] < 2){
  612. $mer=Db::name("system_config_value")
  613. ->where($where)
  614. ->update(
  615. [
  616. "value"=>$data["value"]
  617. ]
  618. );
  619. }
  620. }else{
  621. $mer=Db::name("system_config_value")
  622. ->insert(
  623. [
  624. "config_key"=>"base_commission",
  625. "mer_id"=>$data["mer_id"],
  626. "value"=>$data["value"]
  627. ]
  628. );
  629. }
  630. // 提交事务
  631. Db::commit();
  632. return app('json')->success("开启成功");
  633. } catch (\Exception $e) {
  634. // 回滚事务
  635. Db::rollback();
  636. }
  637. }
  638. public function get_consumption_score(){
  639. $uid=$this->request->uid();
  640. $all = Db::name('merchant_consumption_score_log')
  641. -> where('uid',$uid)
  642. -> select();
  643. //已结算,预估,已释放
  644. $a = $b = $c = 0;
  645. foreach ($all as $key => $value){
  646. if($value['pm'] == 1 && ($value['status'] == 1 || $value['status'] == 3) && $value['order_id'] > 0){
  647. $a += $value['consumption_score'];
  648. }
  649. if($value['pm'] == 1 && $value['status'] == 0 && $value['order_id'] > 0){
  650. $b += $value['consumption_score'];
  651. }
  652. if ($value['pm'] == 2){
  653. $c += $value['consumption_score'];
  654. }
  655. }
  656. $data['settled'] = $a;
  657. $data['predict'] = $b;
  658. $data['release'] = $c;
  659. return app('json')->success($data);
  660. }
  661. //消费分
  662. public function get_consumption_score_list(){
  663. $uid=$this->request->uid();
  664. [$page,$limit] = $this->getPage();
  665. $count = Db::name('merchant_consumption_score_log')
  666. -> where('uid',$uid)
  667. -> count();
  668. $list = Db::name('merchant_consumption_score_log')
  669. -> where('uid',$uid)
  670. -> page($page,$limit)
  671. -> select()
  672. -> each(function ($item){
  673. $item['add_time'] = date('Y-m-d H:i:s',$item['add_time']);
  674. $item['update_time'] = date('Y-m-d H:i:s',$item['update_time']);
  675. return $item;
  676. });
  677. return app('json')->success(['list'=>$list,'count'=>$count]);
  678. }
  679. }