diff --git a/app/admin/controller/shop/LocalStore.php b/app/admin/controller/shop/LocalStore.php index eb22f4a6..b4a96098 100755 --- a/app/admin/controller/shop/LocalStore.php +++ b/app/admin/controller/shop/LocalStore.php @@ -5,10 +5,12 @@ namespace app\admin\controller\shop; use app\admin\logic\groupbuy\GroupbuyLogic; use app\admin\logic\user\UserLogic; use app\common\basics\AdminBase; +use app\common\server\CloudAudioServer; use app\common\server\ConfigServer; use app\common\enum\LocalLifeICBCEnum; use app\admin\logic\shop\LocalStoreLogic; use app\common\server\JsonServer; +use app\common\server\storage\engine\Local; use think\facade\Request; use app\common\utils\UploadAliOSS; use app\admin\validate\shop\LocalStoreValidate; @@ -277,4 +279,35 @@ class LocalStore extends AdminBase { return view(''); } + + public function bind() + { + $id = $this->request->get('lstore_id'); + + if ($this->request->isAjax()) { + $post = $this->request->post(); + $result = LocalStoreLogic::bindCloudAudio($post); + if ($result) { + return JsonServer::success('绑定成功'); + } + + return JsonServer::error('绑定失败'); + } + + return view('', [ + 'lstore_id' => $id, + 'detail' => LocalStoreLogic::getBindAudio($id), + 'message' => str_replace(',', '', CloudAudioServer::MESSAGE) + ]); + } + + public function test() + { + $id = $this->request->get('lstore_id'); + $result = LocalStoreLogic::testCloudAudio($id); + if ($result) { + return JsonServer::success('操作成功'); + } + return JsonServer::error(LocalStoreLogic::getError()); + } } \ No newline at end of file diff --git a/app/admin/logic/shop/LocalStoreLogic.php b/app/admin/logic/shop/LocalStoreLogic.php index e6bfd5e1..f09192e7 100755 --- a/app/admin/logic/shop/LocalStoreLogic.php +++ b/app/admin/logic/shop/LocalStoreLogic.php @@ -5,9 +5,11 @@ namespace app\admin\logic\shop; use app\common\basics\Logic; use app\common\enum\TreatyEnum; use app\common\model\LocalStore; +use app\common\model\localstore\LocalStoreCloudAudio; use app\common\model\LocalStoreOrder; use app\common\model\LocalStoreOrderRecord; use app\common\model\Treaty; +use app\common\server\CloudAudioServer; use app\common\server\ExportExcelServer; use app\common\server\WeChatServer; use EasyWeChat\Factory; @@ -460,4 +462,54 @@ class LocalStoreLogic extends Logic { return GtMcc::where(['parent_id' => 0, 'state' => 1])->field('mcc_id, mccName')->select(); } + + // 国联支付 + public static function getBindAudio($lstore_id) + { + return LocalStoreCloudAudio::where('lstore_id', $lstore_id)->find(); + } + + public static function bindCloudAudio($data) + { + try { + $result = LocalStoreCloudAudio::where('id', $data['id'])->find(); + + $audio = [ + 'lstore_id' => $data['lstore_id'], + 'sn' => $data['sn'], + 'version' => $data['version'] <= 0 ? 1 : $data['version'], + 'message' => $data['message'] ?? CloudAudioServer::MESSAGE, + ]; + if (empty($result)) { + $audio['create_time'] = time(); + return LocalStoreCloudAudio::create($audio); + } + + $audio['update_time'] = time(); + return LocalStoreCloudAudio::where('id', $data['id'])->update($audio); + } catch (\Exception $e) { + self::$error = $e->getMessage(); + return false; + } + } + + public static function testCloudAudio($lstore_id) + { + $data = LocalStoreCloudAudio::where('lstore_id', $lstore_id)->find(); + if (!empty($data)) { + $result = CloudAudioServer::send([ + 'id' => $data['sn'], + 'version' => $data['version'], + 'message' => $data['message'], + ]); + + if ($result['code'] == 1) { + return true; + } + self::$error = $result['msg']; + return false; + } + self::$error = '未配置参数'; + return false; + } } \ No newline at end of file diff --git a/app/admin/view/shop/local_store/bind.html b/app/admin/view/shop/local_store/bind.html new file mode 100755 index 00000000..d7be5a9c --- /dev/null +++ b/app/admin/view/shop/local_store/bind.html @@ -0,0 +1,212 @@ +{layout name="layout2" /} + + +
+
+ + + +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ + +
+ +
+
+
+ + \ No newline at end of file diff --git a/app/admin/view/shop/local_store/lists.html b/app/admin/view/shop/local_store/lists.html index 695fb331..1039ff3f 100755 --- a/app/admin/view/shop/local_store/lists.html +++ b/app/admin/view/shop/local_store/lists.html @@ -66,17 +66,21 @@ @@ -324,6 +328,52 @@ submit.trigger("click"); } }); + }, + bind(obj) { + // 绑定设备 + layer.open({ + type: 2 + , title: "绑定设备" + , content: "{:url('shop.LocalStore/bind')}?lstore_id=" + obj.data.lstore_id + , area: ['90%', '90%'] + , btn: ["确定", "取消"] + , yes: function (index, layero) { + var iframeWindow = window["layui-layer-iframe" + index]; + var submit = layero.find("iframe").contents().find("#addSubmit"); + iframeWindow.layui.form.on("submit(addSubmit)", function (data) { + like.ajax({ + url: "{:url('shop.LocalStore/bind')}", + data: data.field, + type: "POST", + success: function (res) { + if (res.code === 1) { + layui.layer.msg(res.msg); + layer.close(index); + table.reload("like-table-lists", { + where: {}, + page: {cur: 1} + }); + } + } + }); + }); + submit.trigger("click"); + } + }); + }, + test(obj) { + // 测试设备 + like.ajax({ + url: "{:url('shop.LocalStore/test')}?lstore_id=" + obj.data.lstore_id, + type: "POST", + success: function (res) { + if (res.code === 1) { + layui.layer.msg(res.msg); + } + } + }); + + return false } }; like.eventClick(active); diff --git a/app/common/model/localstore/LocalStoreCloudAudio.php b/app/common/model/localstore/LocalStoreCloudAudio.php new file mode 100644 index 00000000..22a2698f --- /dev/null +++ b/app/common/model/localstore/LocalStoreCloudAudio.php @@ -0,0 +1,10 @@ + 1, + ]; + } + return [ + 'code' => 0, + 'msg' => $result['errmsg'] + ]; + } catch (\Exception $e) { + return [ + 'code' => 0, + 'msg' => $e->getMessage() + ]; + } + } + + private static function curlPost($api, $postData) + { + $postData['token'] = self::TOKEN; + + $curl = curl_init(); + + curl_setopt_array($curl, [ + CURLOPT_URL => self::URI . $api, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_ENCODING => "", + CURLOPT_MAXREDIRS => 10, + CURLOPT_TIMEOUT => 30, + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, + CURLOPT_CUSTOMREQUEST => "POST", + CURLOPT_POSTFIELDS => http_build_query($postData), + CURLOPT_HTTPHEADER => [ + "content-type: application/x-www-form-urlencoded" + ], + ]); + + $response = curl_exec($curl); + + $err = curl_error($curl); + if ($err) { + return "CURL Error #:" . $err; + } + return json_decode($response,true); + } +} \ No newline at end of file diff --git a/database/migrations/20241207060757_create_local_store_cloud_audio_table.php b/database/migrations/20241207060757_create_local_store_cloud_audio_table.php new file mode 100644 index 00000000..73ed58ca --- /dev/null +++ b/database/migrations/20241207060757_create_local_store_cloud_audio_table.php @@ -0,0 +1,75 @@ +table('local_store_cloud_audio', ['comment' => '本地生活商家绑定的音响设备']); + + // 创建字段 + $table->addColumn('lstore_id', 'integer', [ + 'limit' => 10, + 'default' => 0, + 'null' => false, + 'comment' => '本地生活商家ID', + ]) + ->addColumn('sn', 'string', [ + 'limit' => 64, + 'default' => '', + 'null' => false, + 'comment' => '设备SN/ID号', + ]) + ->addColumn('version', 'integer', [ + 'limit' => 1, + 'default' => 1, + 'null' => false, + 'comment' => '设备版本号', + ]) + ->addColumn('message', 'string', [ + 'limit' => 32, + 'default' => '', + 'null' => false, + 'comment' => '设备消息提示', + ]) + ->addColumn('create_time', 'integer', [ + 'limit' => 10, + 'default' => 0, + 'null' => false, + 'comment' => '创建时间', + ]) + ->addColumn('update_time', 'integer', [ + 'limit' => 10, + 'default' => 0, + 'null' => false, + 'comment' => '更新时间', + ]) + ->addIndex(['lstore_id'], ['unique' => true, 'name' => 'idx_lstore_id']) + ->addIndex(['sn'], ['unique' => true, 'name' => 'idx_sn']) + ->create(); + } +}