Store.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 https://www.sapixx.com All rights reserved.
  4. * @license Licensed (http://www.apache.org/licenses/LICENSE-2.0).
  5. * @author pillar<ltmn@qq.com>
  6. * 商店管理
  7. */
  8. namespace app\allwin\controller;
  9. use app\allwin\model\WorkerStoreOrder;
  10. use app\allwin\model\AllwinStoreCate;
  11. use app\allwin\model\AllwinStore;
  12. use app\allwin\model\StoreStats;
  13. use app\allwin\model\AllwinStoreChain;
  14. use app\allwin\model\StoreWorker;
  15. use app\allwin\model\AllwinUser;
  16. use app\allwin\model\CouponUser;
  17. use app\allwin\model\Order;
  18. use app\allwin\model\MchIdUser;
  19. use app\allwin\model\StoreUnion;
  20. use app\allwin\model\AllwinUserAgent;
  21. use app\allwin\model\Vip;
  22. use app\allwin\model\AllwinConfig;
  23. use app\common\facade\Inform;
  24. use app\common\facade\AliApi;
  25. use app\common\model\SystemUser;
  26. use think\helper\Time;
  27. use think\facade\Request;
  28. use think\facade\Validate;
  29. class Store extends Common{
  30. public function initialize(){
  31. parent::initialize();
  32. $this->assign('pathMaps',[['name'=>'商家管理','url'=>url("allwin/store/index")]]);
  33. }
  34. /**
  35. * 列表
  36. */
  37. public function index(int $types = 0){
  38. $condition = [];
  39. $time = Request::param('time/d',0);
  40. $starttime = Request::param('starttime/s');
  41. $endtime = Request::param('endtime/s');
  42. if($time){
  43. switch ($time) {
  44. case 2:
  45. list($start, $end) = Time::yesterday();
  46. break;
  47. case 30:
  48. list($start, $end) = Time::month();
  49. break;
  50. case 60:
  51. list($start, $end) = Time::lastMonth();
  52. break;
  53. default:
  54. list($start, $end) = Time::today();
  55. break;
  56. }
  57. $condition[] = ['create_time','>=',$start];
  58. $condition[] = ['create_time','<=',$end];
  59. }else{
  60. if($starttime){
  61. $condition[] = ['create_time','>=',strtotime($starttime)];
  62. }
  63. if($endtime){
  64. $condition[] = ['create_time','<=',strtotime($endtime)];
  65. }
  66. }
  67. $keyword = Request::param('keyword/s');
  68. if(!empty($keyword)){
  69. $condition[] = ['name','like','%'.$keyword.'%'];
  70. }
  71. $view['is_top_num'] = AllwinStore::where($this->mini_program)->where($condition)->where(['is_top' => 1])->count('is_top');
  72. $view['store_num'] = AllwinStore::where($this->mini_program)->where($condition)->count();
  73. $view['lock_num'] = AllwinStore::where($this->mini_program)->where($condition)->where(['is_lock' => 1])->count();
  74. $view['lists'] = AllwinStore::where($this->mini_program)->where($condition)->where(['is_lock' => $types ? 1 : 0])->order('is_top desc,sort desc,id desc')->paginate(20,false,['query' => ['types' => $types,'starttime' => $starttime,'endtime' => $endtime,'time'=>$time]]);
  75. $view['keyword'] = $keyword;
  76. $view['types'] = $types;
  77. $view['time'] = $time;
  78. $view['starttime'] = $starttime;
  79. $view['endtime'] = $endtime;
  80. return view()->assign($view);
  81. }
  82. /**
  83. * 选择商家列表
  84. */
  85. public function selectStore(){
  86. $condition = [];
  87. $condition[] = ['is_lock','=',0];
  88. $view['keyword'] = $this->request->param('keyword/s');
  89. if(!empty($view['keyword'])){
  90. $condition[] = ['name','like','%'.$view['keyword'].'%'];
  91. }
  92. $view['lists'] = AllwinStore::where($this->mini_program)->where($condition)->order('is_top desc,sort desc,id desc')->paginate(20);
  93. $view['input'] = $this->request->param('input');
  94. return view()->assign($view);
  95. }
  96. /**
  97. * 好店预览
  98. */
  99. public function review(int $id){
  100. $condition['id'] = $id;
  101. $view['info'] = AllwinStore::where($condition)->find();
  102. if(!$view['info']){
  103. $this->error('内容不存在');
  104. }
  105. $view['user'] = StoreWorker::where($this->mini_program)->where(['store_id' => $id])->order('id desc')->select();
  106. $view['manage'] = SystemUser::where($this->mini_program)->where(['id' => $view['info']['manage_uid']])->find();
  107. $stats = StoreStats::where($this->mini_program)->where(['store_id' => $id])->find();
  108. if(empty($stats)){
  109. $view['stats']['payment'] = money(0);
  110. $view['stats']['coupon'] = money(0);
  111. $view['stats']['card'] = money(0);
  112. $view['stats']['vip'] = money(0);
  113. }else{
  114. $view['stats'] = $stats;
  115. }
  116. $view['orders'] = Order::where($this->mini_program)->where(['store_id'=>$id,'state' => 1])->order('id desc')->paginate(10,false,['query' => ['id' => $id]]);
  117. return view()->assign($view);
  118. }
  119. /**
  120. * 添加
  121. */
  122. public function add(){
  123. if(request()->isAjax()){
  124. $data = [
  125. 'id' => 0,
  126. 'member_miniapp_id' => $this->member_miniapp_id,
  127. 'manage_uid' => Request::param('manage_uid/d',0),
  128. 'mch_id' => Request::param('mch_id/d',0),
  129. 'charges' => Request::param('charges/d'),
  130. 'cate_id' => Request::param('cate_id/d',0),
  131. 'cate_sid' => Request::param('cate_sid/d',0),
  132. 'code_id' => Request::param('code_id/s'),
  133. 'name' => Request::param('name/s'),
  134. 'type_text' => Request::param('type_text/s'),
  135. 'address' => Request::param('address/s'),
  136. 'longitude' => Request::param('longitude/s'),
  137. 'latitude' => Request::param('latitude/s'),
  138. 'telphone' => Request::param('telphone/s'),
  139. 'tips' => Request::param('tips/s'),
  140. 'tags' => Request::param('tags/s'),
  141. 'img' => Request::param('img/s'),
  142. 'imgs' => Request::param('imgs/a'),
  143. ];
  144. $validate = $this->validate($data,'Store.edit');
  145. if(true !== $validate){
  146. return json(['code'=>0,'msg'=>$validate]);
  147. }
  148. if($data['charges'] > 0 && $data['charges'] <= 6){
  149. return json(['code'=>0,'msg'=>'抱歉~交易服务费禁止小于6‰']);
  150. }
  151. //判断付款码
  152. $result = AllwinStore::where(['code_id' => $data['code_id']])->find();
  153. if($result){
  154. return enjson(0,'付款编码已存在');
  155. }else{
  156. $rel = AllwinStoreChain::where(['code_id' => $data['code_id']])->find();
  157. if($rel){
  158. return enjson(0,'付款编码已存在');
  159. }
  160. }
  161. //判断当前用户是否社群主
  162. if($data['manage_uid']){
  163. $agent = AllwinUserAgent::where(['uid' => $data['manage_uid']])->count();
  164. if($agent){
  165. return json(['code'=>0,'msg'=>'当前用户是【社群主身份】,禁止绑定']);
  166. }
  167. }
  168. if(AllwinStore::edit($data)){
  169. return json(['code'=>200,'url'=>url('allwin/store/index',['cate_id' => $data['cate_id']]),'msg'=>'操作成功']);
  170. }else{
  171. return json(['code'=>0,'msg'=>'操作失败']);
  172. }
  173. }else{
  174. $view['cate'] = AllwinStoreCate::field('name,id')->where($this->mini_program)->where(['parent_id' => 0])->order('sort desc,id desc')->select();
  175. $view['setting'] = AllwinConfig::getConfig($this->member_miniapp_id);
  176. return view()->assign($view);
  177. }
  178. }
  179. //编辑
  180. public function edit(){
  181. if(request()->isAjax()){
  182. $data = [
  183. 'member_miniapp_id' => $this->member_miniapp_id,
  184. 'id' => Request::param('id/d'),
  185. 'original_uid' => Request::param('original_uid/d'),
  186. 'original_mchid' => Request::param('original_mchid/d'),
  187. 'manage_uid' => Request::param('manage_uid/d',0),
  188. 'mch_id' => Request::param('mch_id/d',0),
  189. 'charges' => Request::param('charges/d'),
  190. 'cate_id' => Request::param('cate_id/d',0),
  191. 'cate_sid' => Request::param('cate_sid/d',0),
  192. 'name' => Request::param('name/s'),
  193. 'type_text' => Request::param('type_text/s'),
  194. 'address' => Request::param('address/s'),
  195. 'longitude' => Request::param('longitude/s'),
  196. 'latitude' => Request::param('latitude/s'),
  197. 'telphone' => Request::param('telphone/s'),
  198. 'tips' => Request::param('tips/s'),
  199. 'tags' => Request::param('tags/s'),
  200. 'img' => Request::param('img/s'),
  201. 'imgs' => Request::param('imgs/a'),
  202. ];
  203. $validate = $this->validate($data,'Store.edit');
  204. if(true !== $validate){
  205. return json(['code'=>0,'msg'=>$validate]);
  206. }
  207. if($data['charges'] > 0 && $data['charges'] <= 6){
  208. return json(['code'=>0,'msg'=>'抱歉~交易服务费禁止小于6‰']);
  209. }
  210. //判断当前用户是否社群主
  211. if($data['manage_uid'] != $data['original_uid']){
  212. $agent = AllwinUserAgent::where(['uid' => $data['manage_uid']])->count();
  213. if($agent){
  214. return json(['code'=>0,'msg'=>'绑定的好店店长是【社群主身份】,禁止绑定']);
  215. }
  216. }
  217. if(AllwinStore::edit($data)){
  218. if($data['mch_id'] != $data['original_mchid']){ //删除旧的分账接收方
  219. MchIdUser::where($this->mini_program)->where(['store_id' => $data['id']])->delete();
  220. }
  221. return json(['code'=>200,'url'=>url('store/index',['cate_id' => $data['cate_id']]),'msg'=>'操作成功']);
  222. }else{
  223. return json(['code'=>0,'msg'=>'操作失败']);
  224. }
  225. }else{
  226. $info = AllwinStore::where($this->mini_program)->where(['id' => $this->request->param('id/d')])->find();
  227. if(!$info){
  228. $this->error("404 NOT FOUND");
  229. }
  230. $view['info'] = $info;
  231. $view['imgs'] = json_decode($info['imgs'],true);
  232. $view['cate'] = AllwinStoreCate::field('name,id')->where($this->mini_program)->where(['parent_id' => 0])->order('sort desc,id desc')->select();
  233. $view['cate_sub'] = AllwinStoreCate::field('name,id')->where(['parent_id' => $info['cate_id'],'member_miniapp_id' => $this->member_miniapp_id])->order('sort desc,id desc')->select();
  234. $view['setting'] = AllwinConfig::getConfig($this->member_miniapp_id);
  235. return view()->assign($view);
  236. }
  237. }
  238. /**
  239. * 排序
  240. */
  241. public function sort(){
  242. if(request()->isAjax()){
  243. $data = [
  244. 'sort' => Request::param('sort/d'),
  245. 'id' => Request::param('id/d'),
  246. ];
  247. $validate = $this->validate($data,'Cate.sort');
  248. if(true !== $validate){
  249. return json(['code'=>0,'msg'=>$validate]);
  250. }
  251. $result = AllwinStore::where(['id' => $data['id']])->update(['sort' => $data['sort']]);
  252. if($result){
  253. return json(['code'=>200,'msg'=>'操作成功']);
  254. }else{
  255. return json(['code'=>0,'msg'=>'操作失败']);
  256. }
  257. }
  258. }
  259. /**
  260. * 置顶/取消
  261. * @param integer $id 用户ID
  262. */
  263. public function isTop(int $id){
  264. $result = AllwinStore::isTop($id);
  265. if(!$result){
  266. return json(['code'=>0,'message'=>'操作失败']);
  267. }else{
  268. return json(['code'=>200,'message'=>'操作成功']);
  269. }
  270. }
  271. /**
  272. * 置顶/取消
  273. * @param integer $id 用户ID
  274. */
  275. public function isLock(int $id){
  276. $result = AllwinStore::isLock($id,$this->member_miniapp_id);
  277. if(!$result){
  278. return json(['code'=>0,'message'=>'操作失败']);
  279. }else{
  280. return json(['code'=>200,'message'=>'操作成功']);
  281. }
  282. }
  283. /**
  284. * 设置营业状态
  285. * @param integer $id 用户ID
  286. */
  287. public function setState(int $id){
  288. $info = AllwinStore::where($this->mini_program)->where(['id' => $id])->find();
  289. if(!$info){
  290. return json(['code'=>0,'message'=>'未找到好店']);
  291. }
  292. $info->state = $info->state == 0 ? 1 : 0;
  293. $result = $info->save();
  294. if(!$result){
  295. return json(['code'=>0,'message'=>'操作失败']);
  296. }else{
  297. return json(['code'=>200,'message'=>'操作成功']);
  298. }
  299. }
  300. //删除
  301. public function delete(int $id){
  302. $coupon = model('Coupon')->where($this->mini_program)->where(['store_id' => $id])->count();
  303. if($coupon){
  304. return json(['code'=>403,'msg'=>'请先删除好店优惠券']);
  305. }
  306. $couponUser = CouponUser::where($this->mini_program)->where(['store_id' => $id])->count();
  307. if($couponUser){
  308. return json(['code'=>403,'msg'=>'请先删除用户已领优惠券']);
  309. }
  310. //判断分店
  311. $chain = AllwinStoreChain::where($this->mini_program)->where(['store_id' => $id])->count();
  312. if($chain){
  313. return json(['code'=>403,'msg'=>'请先删除门店或收银台']);
  314. }
  315. //会员卡
  316. $count = model('Card')->where($this->mini_program)->where(['store_id' => $id])->count();
  317. if($count){
  318. return json(['code'=>403,'msg'=>'请先删除好店会员卡']);
  319. }
  320. StoreUnion::unionDelete(['store_id' => $id]); //删除联合商家数据
  321. StoreWorker::where($this->mini_program)->where(['store_id' => $id])->delete(); //删除员工
  322. WorkerStoreOrder::where($this->mini_program)->where(['store_id' => $id])->delete(); //删除开通数据
  323. AllwinStore::where($this->mini_program)->where(['id' => $id])->delete(); //删除好店
  324. return json(['code'=>200,'msg'=>'操作成功']);
  325. }
  326. /**
  327. * 选择所属用户
  328. */
  329. public function selectStoreManage(){
  330. $view['keyword'] = Request::param('keyword');
  331. $view['input'] = Request::param('input');
  332. $condition = [];
  333. if(!empty($view['keyword'])){
  334. if(Validate::isMobile($view['keyword'])){
  335. $condition[] = ['phone_uid','=',$view['keyword']];
  336. }else{
  337. $condition[] = ['nickname','like','%'.$view['keyword'].'%'];
  338. }
  339. }
  340. $agent_uid = AllwinUserAgent::where($this->mini_program)->column('uid');
  341. $view['list'] = SystemUser::where($this->mini_program)->where($condition)->whereNotIn('id',$agent_uid)->order('id desc')->paginate(10,false,['query' => ['input' => $view['input'],'keyword' => $view['keyword']]]);
  342. return view()->assign($view);
  343. }
  344. /**
  345. * 选择所属用户
  346. */
  347. public function isStoreManage(int $user_id){
  348. $worker = StoreWorker::where(['uid' => $user_id])->count();
  349. if($worker){
  350. return json(['code'=>0,'msg'=>'您已是某好店员工,禁止设置为老板']);
  351. }
  352. return json(['code'=>200,'msg'=>'允许选择']);
  353. }
  354. /**
  355. * 给好店添加管理员
  356. */
  357. public function winUser(int $store_id){
  358. if(request()->isAjax()){
  359. $ids = Request::param('ids/s');
  360. if(empty($ids)){
  361. return json(['code'=>0,'msg'=>'请选择要关联的优惠券']);
  362. }
  363. $uid = (array)ids($ids,true);
  364. $worker_uid = StoreWorker::where($this->mini_program)->where(['uid' => $uid])->column('uid'); //查询添加的用户是否在其它点做员工
  365. $uid = array_diff($uid,$worker_uid);//如果存在就去重
  366. $data = [];
  367. foreach ($uid as $key => $value) {
  368. $data[$key]['member_miniapp_id'] = $this->member_miniapp_id;
  369. $data[$key]['uid'] = $value;
  370. $data[$key]['store_id'] = $store_id;
  371. }
  372. $result = StoreWorker::insertAll($data);
  373. if($result){
  374. //批量添加的员工为当前店铺的会员
  375. foreach ($data as $key => $value) {
  376. AllwinUser::editer($value['uid'],$value['store_id']);
  377. //通知到申请者微信
  378. Inform::sms($value['uid'],$this->member_miniapp_id,['title' =>'业务进展通知','type' => '身份变更','state' => '成功','content' =>'您的身份已变更为员工']);
  379. }
  380. return json(['code'=>200,'msg'=>'添加员工成功','data' =>[]]);
  381. }else{
  382. return json(['code'=>0,'msg'=>'添加员工失败']);
  383. }
  384. }else{
  385. //读好好店员工和好店老板的UID,做筛查排除
  386. $uid = StoreWorker::where($this->mini_program)->column('uid'); //好店员工
  387. $keyword = Request::param('keyword');
  388. $condition = [];
  389. $condition[] = ['id','NOT IN',$uid];
  390. if(!empty($keyword)){
  391. if(Validate::isMobile($keyword)){
  392. $condition[] = ['phone_uid','=',$keyword];
  393. }else{
  394. $condition[] = ['nickname','LIKE','%'.$keyword.'%'];
  395. }
  396. }
  397. $view['list'] = SystemUser::where($this->mini_program)->where($condition)->order('id desc')->paginate(20,false,['query' => ['store_id' => $store_id]]);
  398. $view['store_id'] = $store_id;
  399. $view['keyword'] = $keyword;
  400. return view()->assign($view);
  401. }
  402. }
  403. //删除员工
  404. public function delUser(int $id){
  405. $result = StoreWorker::where($this->mini_program)->where(['uid' => $id])->delete();
  406. if($result){
  407. //判断是否创客,如果是创客解除绑定关系
  408. $parent_vip = Vip::where(['user_id' => $id,'is_lock' => 0,'state' => 1])->field('vipcard_id,user_id')->count();
  409. if($parent_vip){
  410. AllwinUser::editer($id,0); //取消店铺关系
  411. }
  412. return json(['code'=>200,'msg'=>'操作成功']);
  413. }else{
  414. return json(['code'=>403,'msg'=>'删除失败']);
  415. }
  416. }
  417. /**
  418. * 设置好店收银员
  419. * @param integer $id 用户ID
  420. */
  421. public function isCashier(int $id){
  422. $result = StoreWorker::setWorker($id,$this->member_miniapp_id);
  423. if(!$result){
  424. return json(['code'=>0,'message'=>'操作失败']);
  425. }else{
  426. return json(['code'=>200,'message'=>'操作成功']);
  427. }
  428. }
  429. /**
  430. * 读取好店分类
  431. * @return void
  432. */
  433. public function storecate(int $cate_id){
  434. $cate = AllwinStoreCate::where(['member_miniapp_id' => $this->member_miniapp_id,'parent_id' => $cate_id])->field('id,name')->order('sort desc,id desc')->select();
  435. return json(['code'=>200,'msg'=>'成功','data' => $cate]);
  436. }
  437. /**
  438. * 根据地址位置转账
  439. * @return void
  440. */
  441. public function baidu($address){
  442. $view['address'] = $address;
  443. return view()->assign($view);
  444. }
  445. /**
  446. * 根据地址位置读取地址
  447. * @return void
  448. */
  449. public function maps($address){
  450. $rel = AliApi::address($address);
  451. if(!$rel){
  452. return enjson(0,'请确认是否要帐号欠费');
  453. }
  454. $address = $rel['geocodes'][0];
  455. $location = explode(',',$address['location']);
  456. return enjson(200,'成功',$location);
  457. }
  458. /**
  459. * 连锁门店
  460. */
  461. public function chainStore(){
  462. $store_id = $this->request->param('store_id/d');
  463. $view['lists'] = AllwinStoreChain::where(['store_id' => $store_id])->order('sort desc,id desc')->paginate(20);
  464. $view['store_id'] = $store_id;
  465. return view()->assign($view);
  466. }
  467. //编辑
  468. public function chainStoreEdit(int $store_id){
  469. if(request()->isAjax()){
  470. $data = [
  471. 'id' => Request::param('id/d',0),
  472. 'store_id' => $store_id,
  473. 'code_id' => Request::param('code_id/s'),
  474. 'title' => Request::param('title/s'),
  475. 'address' => Request::param('address/s'),
  476. 'longitude' => Request::param('longitude/s'),
  477. 'latitude' => Request::param('latitude/s'),
  478. 'telphone' => Request::param('telphone/s'),
  479. 'update_time' => time(),
  480. 'member_miniapp_id' => $this->member_miniapp_id
  481. ];
  482. $validate = $this->validate($data,'Store.chain');
  483. if(true !== $validate){
  484. return json(['code'=>0,'msg'=>$validate]);
  485. }
  486. //判断付款码
  487. $result = AllwinStore::where(['code_id' => $data['code_id']])->find();
  488. if($result){
  489. return enjson(0,'付款编码已存在');
  490. }else{
  491. $code_rel = AllwinStoreChain::where('id','<>',$data['id'])->where(['code_id' => $data['code_id']])->find();
  492. if($code_rel){
  493. return enjson(0,'付款编码已存在');
  494. }
  495. }
  496. if($data['id']){
  497. $rel = AllwinStoreChain::update($data);
  498. }else{
  499. $rel = AllwinStoreChain::create($data);
  500. }
  501. if($rel){
  502. return json(['code'=>200,'url'=>url('store/chainStore',['store_id' => $store_id]),'msg'=>'操作成功']);
  503. }else{
  504. return json(['code'=>0,'msg'=>'操作失败']);
  505. }
  506. }else{
  507. $view['id'] = Request::param('id/d',0);
  508. $view['info'] = AllwinStoreChain::where(['store_id' => $store_id,'id' => $view['id']])->find();
  509. $view['store_id'] = $store_id;
  510. return view()->assign($view);
  511. }
  512. }
  513. //删除
  514. public function chainDelete(int $id){
  515. AllwinStoreChain::where($this->mini_program)->where(['id' =>$id])->delete(); //删除好店
  516. return json(['code'=>200,'msg'=>'操作成功']);
  517. }
  518. /**
  519. * 门店排序
  520. */
  521. public function chainSort(){
  522. if(request()->isAjax()){
  523. $data = [
  524. 'sort' => Request::param('sort/d'),
  525. 'id' => Request::param('id/d'),
  526. ];
  527. $validate = $this->validate($data,'Cate.sort');
  528. if(true !== $validate){
  529. return json(['code'=>0,'msg'=>$validate]);
  530. }
  531. $result = AllwinStoreChain::where(['id' => $data['id']])->update(['sort' => $data['sort']]);
  532. if($result){
  533. return json(['code'=>200,'msg'=>'操作成功']);
  534. }else{
  535. return json(['code'=>0,'msg'=>'操作失败']);
  536. }
  537. }
  538. }
  539. /**
  540. * 判断商户是否重复
  541. * @return boolean
  542. */
  543. public function codeid(){
  544. $store_id = Request::param('store_id/d',0);
  545. $code_id = Request::param('param/d');
  546. if(empty($code_id)){
  547. return json(['status'=>'n','info'=>'未输入付款编码']);
  548. }
  549. if(strlen($code_id) != 12){
  550. return json(['status'=>'n','info'=>'付款编码必须12位']);
  551. }
  552. if($store_id){
  553. $result = AllwinStore::where('id','<>',$store_id)->where(['code_id' => $code_id])->find();
  554. }else{
  555. $result = AllwinStore::where(['code_id' => $code_id])->find();
  556. }
  557. if($result){
  558. return json(['status'=>'n','info'=>'付款编码已存在']);
  559. }
  560. $rel = AllwinStoreChain::where(['code_id' => $code_id])->find();
  561. if($rel){
  562. return json(['status'=>'n','info'=>'付款编码已存在']);
  563. }
  564. return json(['status'=>'y','info'=>'付款编码可用']);
  565. }
  566. /**
  567. * 分类类型
  568. * @param integer $id 用户ID
  569. */
  570. public function chainType(int $id){
  571. $result = AllwinStoreChain::isType($id);
  572. if(!$result){
  573. return json(['code'=>0,'message'=>'操作失败']);
  574. }else{
  575. return json(['code'=>200,'message'=>'操作成功']);
  576. }
  577. }
  578. /**
  579. * 判断商户是否重复
  580. * @return boolean
  581. */
  582. public function chainCodeid(){
  583. $chain_id = Request::param('chain_id/d',0);
  584. $code_id = Request::param('param/d');
  585. if(empty($code_id)){
  586. return json(['status'=>'n','info'=>'未输入付款编码']);
  587. }
  588. if(strlen($code_id) != 12){
  589. return json(['status'=>'n','info'=>'付款编码必须12位']);
  590. }
  591. if($chain_id){
  592. $result = AllwinStoreChain::where('id','<>',$chain_id)->where(['code_id' => $code_id])->find();
  593. }else{
  594. $result = AllwinStoreChain::where(['code_id' => $code_id])->find();
  595. }
  596. if($result){
  597. return json(['status'=>'n','info'=>'付款编码已存在']);
  598. }
  599. $rel = AllwinStore::where(['code_id' => $code_id])->find();
  600. if($rel){
  601. return json(['status'=>'n','info'=>'付款编码已存在']);
  602. }
  603. return json(['status'=>'y','info'=>'付款编码可用']);
  604. }
  605. }