list.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. <?php
  2. use common\services\xhWifiService;
  3. use common\components\util;
  4. ?>
  5. <div class="page-title">
  6. <div class="title-env">
  7. <h1 class="title">店铺管理</h1>
  8. </div>
  9. <div class="breadcrumb-env">
  10. <ol class="breadcrumb bc-1">
  11. <li>
  12. <a href="/"><i class="fa-home"></i>Home</a>
  13. </li>
  14. <li>
  15. <a href="javascript:void(0)">商城管理</a>
  16. </li>
  17. <li class="active">
  18. <strong>店铺管理</strong>
  19. </li>
  20. </ol>
  21. </div>
  22. </div>
  23. <div class="panel panel-default">
  24. <div class="panel-body">
  25. <div class="dataTables_wrapper form-inline dt-bootstrap no-footer">
  26. <div class="row">
  27. <form action="" method="GET">
  28. <div class="col-xs-6" style="width:90%;">
  29. <div class="dataTables_length">
  30. <a href="javascript:void(0)" name="" class="btn btn-secondary btn-single" id="init-store" style="">新建门店</a>
  31. </div>
  32. </div>
  33. </form>
  34. </div>
  35. <div class="table-responsive">
  36. <table class="table table-bordered table-striped table-hover" >
  37. <thead>
  38. <tr class="active">
  39. <th class="no-sorting hidden-xs"><input type="checkbox"></th>
  40. <th class="hidden-xs">ID</th>
  41. <th>门店名称</th>
  42. <th class="hidden-xs">图片</th>
  43. <th class="hidden-xs">地址</th>
  44. <th class="hidden-xs">电话</th>
  45. <th class="hidden-xs">创建时间</th>
  46. <th class="hidden-xs">状态</th>
  47. <th>操作</th>
  48. </tr>
  49. </thead>
  50. <tbody class="middle-align">
  51. <?php if(!empty($shop)){ foreach($shop as $key => $val){
  52. $shopId = $val['id'];
  53. $wifi = [];
  54. if(!empty($shopId)){
  55. $wifi = xhWifiService::getListByShopId($shopId);
  56. }
  57. ?>
  58. <tr>
  59. <td class="hidden-xs"><input type="checkbox"></td>
  60. <td class="hidden-xs"><?= $val['id'] ?></td>
  61. <td><?= $val['branchName'] ?></td>
  62. <td class="hidden-xs"> </td>
  63. <td class="hidden-xs"><?= $val['shopAddress'] ?></td>
  64. <td class="hidden-xs"><?= $val['telephone'] ?></td>
  65. <td class="hidden-xs"><?= date("Y-m-d H:i",strtotime($val['createTime'])) ?></td>
  66. <td class="hidden-xs"><?php util::echoStatus($val['status'], 'xhShop')?></td>
  67. <td>
  68. <a href="javascript:void(0)" class="btn btn-secondary btn-sm btn-icon icon-left free-wifi-btn" shop_id="<?= $val['shopId']?>">WIFI设置</a>
  69. <a href="javascript:void(0)" onclick="createQrCode(<?= $val['shopId'] ?>, <?= $val['status']?>, $(this));" data-url="/merchant/gathering-url?shopId=<?= $val['shopId']?>" class="btn btn-secondary btn-sm btn-icon icon-left">收款码 </a>
  70. <?php
  71. if($val['status'] == 2){
  72. ?>
  73. <a href="javascript:void(0)" onclick="createQrCode(<?= $val['shopId'] ?>, <?= $val['status']?>, $(this));" data-url="/merchant/gathering-url?shopId=<?= $val['shopId']?>" class="btn btn-secondary btn-sm btn-icon icon-left">收款码 </a>
  74. <?php
  75. }
  76. ?>
  77. </td>
  78. </tr>
  79. <?php } }?>
  80. </tbody>
  81. </table>
  82. </div>
  83. <div class="row">
  84. <div>
  85. <div class="dataTables_paginate paging_simple_numbers" style="float:right;padding-top:0px;margin-right:15px;">
  86. <?= $paging ?>
  87. </div>
  88. </div>
  89. </div>
  90. </div>
  91. </div>
  92. </div>
  93. <!-- footer -->
  94. <?php
  95. use backend\widgets\FooterWidget;
  96. ?>
  97. <?= FooterWidget::widget()?>
  98. <!-- footer -->
  99. <script>
  100. $(function(){
  101. //创建门店操作
  102. $("#init-store").click(function(){
  103. $('#create-store-model').modal('show');
  104. });
  105. //确认创建门店
  106. $("button[name=createStoreConfirmButton]").click(function(){
  107. var storeName = $("#create-store-model .modal-body input[name=storeName]").val();
  108. return false;
  109. if(storeName.length <= 0){
  110. xhPopMsg('请输入分店名称',1300);
  111. return;
  112. }
  113. $("button[name=createStoreConfirmButton]").attr('submitStatus','yes');
  114. setTimeout(function(){
  115. $("button[name=createStoreConfirmButton]").attr('submitStatus','no');
  116. },5000);
  117. $.ajax({
  118. type: "POST",
  119. url: "/shop/apply-store",
  120. data:{'storeName':storeName, '_csrf':"<?= Yii::$app->request->csrfToken;?>"},
  121. dataType: "json",
  122. //在请求之前调用的函数
  123. beforeSend:function(){
  124. xhPopMsg('门店生成中…');
  125. },
  126. success:function(data){
  127. console.log(data);
  128. if(data.errcode == 0){
  129. xhPopMsg('门店创建成功!');
  130. setTimeout(function(){
  131. window.location.reload();
  132. },1000);
  133. }else{
  134. xhPopMsg('出错,原因:'+data.errmsg,1300);
  135. }
  136. },
  137. //调用执行后调用的函数
  138. complete: function(XMLHttpRequest, textStatus){
  139. //alert(XMLHttpRequest.responseText);
  140. //alert(textStatus);
  141. //HideLoading();
  142. },
  143. //调用出错执行的函数
  144. error: function(){
  145. //请求出错处理
  146. }
  147. });
  148. });
  149. $.getWifiCode = function(shopId){
  150. var wifiData;
  151. $.ajax({
  152. url: '/shop/get-wifi-code',
  153. type: 'POST',
  154. data: {'_csrf':"<?= Yii::$app->request->csrfToken;?>", 'shopId':shopId},
  155. dataType: 'json',
  156. async: false,
  157. success:function(data){
  158. if(data.code == 'success'){
  159. //console.log(data.data);
  160. wifiData = data.data;
  161. }else if(data.code == 'downLoadImgError') {
  162. xhPopMsg(data.msg);
  163. }else{
  164. //xhPopMsg(data.msg, 1300);
  165. xhPopMsg('请先点击 免费WIFI设置!');
  166. }
  167. },
  168. error:function(){
  169. xhPopMsg('request error');
  170. }
  171. });
  172. return wifiData;
  173. };
  174. //wifi密码设置
  175. $(".free-wifi-btn").click(function(){
  176. var shopId = $(this).attr('shop_id');
  177. var wifiData = $.getWifiCode(shopId);
  178. if(wifiData.ssid != ''){
  179. $("#set-wifi-model .form-horizontal input[name=wifiName]").val(wifiData.ssid);
  180. }
  181. if(wifiData.ssidPassword != ''){
  182. $("#set-wifi-model .form-horizontal input[name=wifiCode]").val(wifiData.ssidPassword);
  183. }
  184. if(wifiData.ssid != '' && wifiData.ssidPassword != ''){
  185. $("button[name=wifiConfirmBtn]").html('修改');
  186. }
  187. $("#set-wifi-model .form-horizontal input[name=shopId]").val(shopId);
  188. $('#set-wifi-model').modal('show');
  189. });
  190. //ssid和密码必须有一个以大写字母“WX”开头
  191. $("button[name=wifiConfirmBtn]").click(function(){
  192. var wifiName = $("#set-wifi-model .form-horizontal input[name=wifiName]").val();
  193. var wifiCode = $("#set-wifi-model .form-horizontal input[name=wifiCode]").val();
  194. var shopId = $("#set-wifi-model .form-horizontal input[name=shopId]").val();
  195. var action = 'add';//默认新增创建
  196. if(wifiName.length <= 0){
  197. xhPopMsg('请输入 WIFI 名称', 1500);
  198. return;
  199. }
  200. if(wifiCode.length <= 0){
  201. xhPopMsg('请输入 WIFI 密码', 1500);
  202. return;
  203. }
  204. if(wifiCode.length < 8){
  205. xhPopMsg('不少于8个字符', 1500);
  206. return;
  207. }
  208. if(wifiCode.length > 32){
  209. xhPopMsg('最多24个字符', 1500);
  210. return;
  211. }
  212. if(wifiCode.substring(0, 1) != 'W' || wifiCode.substring(1, 2) != 'X'){
  213. xhPopMsg('WIFI 密码必须以 WX 字母开头', 1500);
  214. $("#set-wifi-model .form-horizontal input[name=wifiCode]").val('WX');
  215. return;
  216. }
  217. $("button[name=wifiConfirmBtn]").attr('disabled', true);
  218. if($(this).html() == '修改'){
  219. action = 'update';
  220. }
  221. $.ajax({
  222. type: "POST",
  223. url: "/shop/create-wifi",
  224. data:{'wifiName':wifiName, 'wifiCode': wifiCode, 'shopId': shopId, 'action': action,'_csrf':"<?= Yii::$app->request->csrfToken;?>"},
  225. dataType: "json",
  226. //在请求之前调用的函数
  227. beforeSend:function(){
  228. xhPopMsg('wifi设置中…');
  229. },
  230. success:function(data){
  231. console.log(data);
  232. if(data.code == 'success'){
  233. xhPopMsg('微信wifi'+data.msg);
  234. $('#set-wifi-model').modal('hide');
  235. }else{
  236. xhPopMsg(data.msg, 1500);
  237. }
  238. },
  239. //调用执行后调用的函数
  240. complete: function(XMLHttpRequest, textStatus){
  241. },
  242. //调用出错执行的函数
  243. error: function(){
  244. //请求出错处理
  245. xhPopMsg('request error');
  246. }
  247. });
  248. $("button[name=wifiConfirmBtn]").attr('disabled', false);
  249. });
  250. });
  251. function delStore(id, shopId, currentObj) {
  252. var title = '提示';
  253. var response = currentObj.attr('data-msg');
  254. var url = currentObj.attr('data-url');
  255. $('#modal-common .modal-title').html(title);
  256. $('#modal-common .modal-body').html(response);
  257. $('#modal-common .btn-white').html('取消');
  258. $('#modal-common .btn-info').html('确定');
  259. $('#modal-common').modal('show', {
  260. backdrop: 'static'
  261. });
  262. $('#modal-common .btn-info').on('click', function() {
  263. $.ajax({
  264. type: "POST",
  265. url: url,
  266. data: {
  267. 'poiId': id,
  268. 'shopId': shopId,
  269. '_csrf': "<?=Yii::$app->request->csrfToken;?>"
  270. },
  271. dataType: "json",
  272. success: function(data) {
  273. if (data.code == 'success') {
  274. $('#modal-common').modal('hide');
  275. currentObj.parents('tr').remove();
  276. xhPopMsg(data.msg);
  277. } else {
  278. xhPopMsg(data.msg+': '+data.data.errmsg);
  279. }
  280. },
  281. error: function(msg) {
  282. xhPopMsg('error');
  283. }
  284. })
  285. })
  286. }
  287. function createQrCode(shopId, status, currentObj){
  288. var wifiData = $.getWifiCode(shopId);
  289. var suffixUrl = currentObj.attr('data-url');
  290. if(wifiData.ssid == '' || wifiData.ssidPassword == ''){
  291. xhPopMsg('请先点击 免费WIFI设置!', 2000);
  292. return;
  293. }
  294. if(status != 2){
  295. xhPopMsg('门店审核通过才能设置哦!', 2000);
  296. //return;
  297. }
  298. if(wifiData.avaibleDev == 0){
  299. xhPopMsg('请先把无线路由器改设成 之前生成的wifi名称与密码,并连接上', 3000);
  300. return;
  301. }
  302. var webUrl = "<?= Yii::$app->request->hostInfo; ?>";
  303. //alert(webUrl + suffixUrl);
  304. window.location.href = webUrl + suffixUrl;
  305. }
  306. </script>
  307. <!-- modal 创建门店 -->
  308. <div class="modal fade" id="create-store-model" >
  309. <div class="modal-dialog" style="height:350px;">
  310. <div class="modal-content">
  311. <div class="modal-header">
  312. <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
  313. <h4 class="modal-title">创建门店</h4>
  314. </div>
  315. <div class="modal-body">
  316. <div class="row">
  317. <div class="col-md-6">
  318. <div class="form-group">
  319. <label for="field-1" class="control-label">门店名:</label>
  320. <input type="tel" class="form-control" placeholder="" name="storeName" value="">
  321. <ban style="font-size: 11px; color: red;">* 不应包含地区信息,不应与门店名有重复<ban>
  322. </div>
  323. </div>
  324. </div>
  325. </div>
  326. <div class="modal-footer">
  327. <button type="button" class="btn btn-info" name="createStoreConfirmButton">确认</button>
  328. <button type="button" class="btn btn-white" data-dismiss="modal">取消</button>
  329. </div>
  330. </div>
  331. </div>
  332. </div>
  333. <!-- modal wifi密码设置 -->
  334. <div class="modal fade" id="set-wifi-model" >
  335. <div class="modal-dialog">
  336. <div class="modal-content">
  337. <div class="modal-header">
  338. <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
  339. <h4 class="modal-title">wifi密码设置</h4>
  340. </div>
  341. <form class="form-horizontal" role="form" style="margin:12px 20px 8px -5px;">
  342. <input type="hidden" name="shopId">
  343. <div class="form-group">
  344. <label for="wifiname" class="col-sm-3 control-label">WIFI名称:</label>
  345. <div class="col-sm-8">
  346. <input type="text" class="form-control" name="wifiName" placeholder="WiFi名称(32个字符以内)">
  347. </div>
  348. </div>
  349. <div class="form-group">
  350. <label for="code" class="col-sm-3 control-label">WIFI密码:</label>
  351. <div class="col-sm-8">
  352. <input type="text" class="form-control" name="wifiCode" placeholder="以大写字母“WX”开头(不能包含中文字符)">
  353. </div>
  354. </div>
  355. </form>
  356. <div class="modal-footer">
  357. <button type="button" class="btn btn-info" name="wifiConfirmBtn">确认</button>
  358. <button type="button" class="btn btn-white" data-dismiss="modal">取消</button>
  359. </div>
  360. </div>
  361. </div>
  362. </div>