ShopExtClass.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. <?php
  2. namespace biz\shop\classes;
  3. use bizHd\purchase\classes\PurchaseClass;
  4. use bizHd\work\classes\WorkClass;
  5. use common\components\dict;
  6. use linslin\yii2\curl;
  7. use biz\base\classes\BaseClass;
  8. class ShopExtClass extends BaseClass
  9. {
  10. public static $baseFile = '\biz\shop\models\ShopExt';
  11. public static function orderUpdateRemind($shopExt, $order)
  12. {
  13. $sendNum = $order->sendNum ?? 0;
  14. $sound = '请注意,' . $sendNum . '号单有修改';
  15. if ($order->fromType == 4) {
  16. $mtSn = $order->thirdSn ?? 0;
  17. $sound = '请注意,美团' . $mtSn . '号单有修改';
  18. }
  19. $hasSh = 0;
  20. $hasHs = 0;
  21. $workList = WorkClass::getAllByCondition(['orderId' => $order->id], null, '*', null, true);
  22. if (!empty($workList)) {
  23. foreach ($workList as $work) {
  24. if ($work->status == 0) {
  25. $sh = $work->sh ?? 0;
  26. if ($sh == 0) {
  27. $hasHs = 1;
  28. } else {
  29. $hasSh = 1;
  30. }
  31. }
  32. }
  33. }
  34. if ($hasHs == 1) {
  35. $lbSn = $order->fromType == 4 ? $shopExt->mtLbSn : $shopExt->makeLbSn;
  36. $lbVersion = $order->fromType == 4 ? $shopExt->mtLbVersion : $shopExt->makeLbVersion;
  37. $url = "https://speaker.17laimai.cn/notify.php?id={$lbSn}&token=HK1626595800&version={$lbVersion}&message=" . $sound;
  38. $curl = new curl\Curl();
  39. $curl->get($url);
  40. }
  41. if ($hasSh == 1) {
  42. $lbSn = $shopExt->lbSn ?? '';
  43. $lbVersion = $shopExt->lbVersion;
  44. $url = "https://speaker.17laimai.cn/notify.php?id={$lbSn}&token=HK1626595800&version={$lbVersion}&message=" . $sound;
  45. $curl = new curl\Curl();
  46. $curl->get($url);
  47. }
  48. }
  49. public static function orderCancelRemind($shopExt, $order)
  50. {
  51. $sendNum = $order->sendNum ?? 0;
  52. $hasSh = 0;
  53. $hasHs = 0;
  54. $workList = WorkClass::getAllByCondition(['orderId' => $order->id], null, '*', null, true);
  55. if (!empty($workList)) {
  56. foreach ($workList as $work) {
  57. if ($work->status == 2) {
  58. $sh = $work->sh ?? 0;
  59. if ($sh == 0) {
  60. $hasHs = 1;
  61. } else {
  62. $hasSh = 1;
  63. }
  64. $sound = '请注意,' . $sendNum . '号单已被取消';
  65. if ($order->fromType == 4) {
  66. $mtSn = $order->thirdSn ?? 0;
  67. $sound = '请注意,美团' . $mtSn . '号单已被取消';
  68. }
  69. }
  70. if ($work->preNum > $work->num && $work->status == 0) {
  71. $sh = $work->sh ?? 0;
  72. if ($sh == 0) {
  73. $hasHs = 1;
  74. } else {
  75. $hasSh = 1;
  76. }
  77. $sound = '请注意,' . $sendNum . '号单有修改';
  78. if ($order->fromType == 4) {
  79. $mtSn = $order->thirdSn ?? 0;
  80. $sound = '请注意,美团' . $mtSn . '号单有修改';
  81. }
  82. }
  83. }
  84. }
  85. if ($hasHs == 1) {
  86. $lbSn = $order->fromType == 4 ? $shopExt->mtLbSn : $shopExt->makeLbSn;
  87. $lbVersion = $order->fromType == 4 ? $shopExt->mtLbVersion : $shopExt->makeLbVersion;
  88. $url = "https://speaker.17laimai.cn/notify.php?id={$lbSn}&token=HK1626595800&version={$lbVersion}&message=" . $sound;
  89. $curl = new curl\Curl();
  90. $curl->get($url);
  91. }
  92. if ($hasSh == 1) {
  93. $lbSn = $shopExt->lbSn ?? '';
  94. $lbVersion = $shopExt->lbVersion;
  95. $url = "https://speaker.17laimai.cn/notify.php?id={$lbSn}&token=HK1626595800&version={$lbVersion}&message=" . $sound;
  96. $curl = new curl\Curl();
  97. $curl->get($url);
  98. }
  99. }
  100. //新制作单提示
  101. public static function newWorkRemind($shopExt, $order)
  102. {
  103. $lbSn = $order->fromType == 4 ? $shopExt->mtLbSn : $shopExt->makeLbSn;
  104. $lbVersion = $order->fromType == 4 ? $shopExt->mtLbVersion : $shopExt->makeLbVersion;
  105. if (empty($lbSn)) {
  106. return false;
  107. }
  108. $sound = "您有新的制作单";
  109. $reachDate = $order->reachDate ?? '';
  110. if ($order->sendType == 1) {
  111. if (!empty($reachDate) && $reachDate != '0000-00-00') {
  112. $readPeriod = $order->reachPeriod ?? 0;
  113. $period = explode(':', $readPeriod);
  114. $periodName = implode($period, '点');
  115. if ($reachDate == date("Y-m-d")) {
  116. $sound .= ',今天' . $periodName . "分到店自取";
  117. } elseif ($reachDate == date("Y-m-d", strtotime("+1 day"))) {
  118. $sound .= ',明天' . $periodName . "分到店自取";
  119. } elseif ($reachDate == date("Y-m-d", strtotime("+2 day"))) {
  120. $sound .= ',后天' . $periodName . "分到店自取";
  121. } else {
  122. $sound .= ',' . date("d", strtotime($reachDate)) . '号' . $periodName . "分到店自取";
  123. }
  124. } else {
  125. $sound .= ",客户到店自取";
  126. }
  127. } else {
  128. if (!empty($reachDate) && $reachDate != '0000-00-00') {
  129. $readPeriod = $order->reachPeriod ?? 0;
  130. $period = explode(':', $readPeriod);
  131. $periodName = implode($period, '点');
  132. if ($reachDate == date("Y-m-d")) {
  133. $sound .= ',今天' . $periodName . "分前配送";
  134. } elseif ($reachDate == date("Y-m-d", strtotime("+1 day"))) {
  135. $sound .= ',明天' . $periodName . "分前配送";
  136. } elseif ($reachDate == date("Y-m-d", strtotime("+2 day"))) {
  137. $sound .= ',后天' . $periodName . "分前配送";
  138. } else {
  139. $sound .= date("d", strtotime($reachDate)) . '号' . $periodName . "分前配送";
  140. }
  141. }
  142. }
  143. $url = "https://speaker.17laimai.cn/notify.php?id={$lbSn}&token=HK1626595800&version={$lbVersion}&message=" . $sound;
  144. $curl = new curl\Curl();
  145. $curl->get($url);
  146. $curl->get($url);
  147. return true;
  148. }
  149. //花店采购供货商端播放声音
  150. public static function hdCgGhsReport($orderSn)
  151. {
  152. $cg = PurchaseClass::getByCondition(['orderSn' => $orderSn], true);
  153. if (isset($cg->onlinePay) && $cg->onlinePay == dict::getDict('onlinePay', 'yes')) {
  154. $saleId = $cg->saleId ?? 0;
  155. $order = \bizGhs\order\classes\OrderClass::getById($saleId, true);
  156. if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'noNeed')) {
  157. $shopId = $order->shopId ?? 0;
  158. $shopExt = ShopExtClass::getByCondition(['shopId' => $shopId], true);
  159. if (isset($shopExt->lbSn) && !empty($shopExt->lbSn)) {
  160. $actPrice = floatval($order->actPrice) ?? 0;
  161. $payWay = $order->payWay ?? dict::getDict('payWay', 'wxPay');
  162. $sound = $payWay == dict::getDict('payWay', 'wxPay') ? "微信收款{$actPrice}元" : "支付宝收款{$actPrice}元";
  163. $url = "https://speaker.17laimai.cn/notify.php?id={$shopExt->lbSn}&token=HK1626595800&version={$shopExt->lbVersion}&message=" . $sound;
  164. $curl = new curl\Curl();
  165. $curl->get($url);
  166. }
  167. }
  168. //app新订单通知
  169. //NoticeClass::ghsNewOrderNotice($order);
  170. }
  171. }
  172. public static function pleasePayReport($order)
  173. {
  174. $shopId = $order->shopId ?? 0;
  175. $shopExt = ShopExtClass::getByCondition(['shopId' => $shopId], true);
  176. if (isset($shopExt->lbSn) && !empty($shopExt->lbSn)) {
  177. $mainPay = $order->mainPay ? floatval($order->mainPay) : 0;
  178. $sound = $mainPay . '元,请出示付款码';
  179. $url = "https://speaker.17laimai.cn/notify.php?id={$shopExt->lbSn}&token=HK1626595800&version={$shopExt->lbVersion}&message=" . $sound;
  180. $curl = new curl\Curl();
  181. $curl->get($url);
  182. }
  183. }
  184. //供货商收银台 ssh 20230421
  185. public static function ghsPleasePayReport($order)
  186. {
  187. $shopId = $order->shopId ?? 0;
  188. $shopExt = ShopExtClass::getByCondition(['shopId' => $shopId], true);
  189. if (isset($shopExt->lbSn) && !empty($shopExt->lbSn)) {
  190. $mainPay = $order->actPrice ? floatval($order->actPrice) : 0;
  191. $sound = $mainPay . '元,请出示付款码';
  192. $url = "https://speaker.17laimai.cn/notify.php?id={$shopExt->lbSn}&token=HK1626595800&version={$shopExt->lbVersion}&message=" . $sound;
  193. $curl = new curl\Curl();
  194. // 复杂分支/关键逻辑:设置 cURL 连接和执行超时,并强制使用 IPv4,防止因外部音箱接口卡顿或 DNS 解析慢拖垮收银结账主进程
  195. $curl->setOption(CURLOPT_CONNECTTIMEOUT, 1); // 连接超时限制为 1 秒,避免网络握手长时间卡死
  196. $curl->setOption(CURLOPT_TIMEOUT, 1); // 总执行时间限制为 1 秒,避免请求挂起时间过长
  197. $curl->setOption(CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); // 强制 IPv4 解析,防止 IPv6 解析超时重试
  198. $curl->get($url);
  199. }
  200. }
  201. /**
  202. * 零售花店收款声音播放
  203. * 职责:向外部音箱接口发送语音播报请求,提示商户收款成功(零售端)
  204. * 入参:ActiveRecord $order (订单模型实例)
  205. * 返回:bool (是否成功触发播报)
  206. * 副作用:发送外部 HTTP 网络请求
  207. * 关键边界:
  208. * 1. 仅限门店订单、在线支付且已付款的订单播报
  209. * 2. 优化:设置极短的 cURL 连接超时与执行超时限制,并强制使用 IPv4 解析,防止因外部音箱接口延迟拖垮收银支付主流程
  210. */
  211. public static function hdGatheringReport($order)
  212. {
  213. if ($order->fromType != dict::getDict("fromType", "shop")) {
  214. //非门店订单不播报语音
  215. return false;
  216. }
  217. if ($order->onlinePay == dict::getDict('onlinePay', 'not')) {
  218. //非在线支付的不播报
  219. return false;
  220. }
  221. if ($order->payStatus != 1) {
  222. //还没有付款订单不播报
  223. return false;
  224. }
  225. $shopId = $order->shopId ?? 0;
  226. $shopExt = ShopExtClass::getByCondition(['shopId' => $shopId], true);
  227. if (isset($shopExt->lbSn) && !empty($shopExt->lbSn)) {
  228. $actPrice = $order->mainPay ? floatval($order->mainPay) : 0;
  229. $payWay = $order->payWay ?? dict::getDict('payWay', 'wxPay');
  230. $sound = $payWay == dict::getDict('payWay', 'wxPay') ? "微信收款{$actPrice}元,谢谢惠顾,欢迎下次光临" : "支付宝收款{$actPrice}元,谢谢惠顾,欢迎下次光临";
  231. $url = "https://speaker.17laimai.cn/notify.php?id={$shopExt->lbSn}&token=HK1626595800&version={$shopExt->lbVersion}&message=" . $sound;
  232. $curl = new curl\Curl();
  233. // 复杂分支/关键逻辑:设置 cURL 连接和执行超时,并强制使用 IPv4,防止因外部音箱接口卡顿或 DNS 解析慢拖垮收银结账主进程
  234. $curl->setOption(CURLOPT_CONNECTTIMEOUT, 1); // 连接超时限制为 1 秒,避免网络握手长时间卡死
  235. $curl->setOption(CURLOPT_TIMEOUT, 1); // 总执行时间限制为 1 秒,避免请求挂起时间过长
  236. $curl->setOption(CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); // 强制 IPv4 解析,防止 IPv6 解析超时重试
  237. $curl->get($url);
  238. }
  239. }
  240. public static function skRechargeReport($recharge)
  241. {
  242. if (empty($recharge)) {
  243. return false;
  244. }
  245. if ($recharge->payStatus != 1) {
  246. //还没有付款订单不播报
  247. return false;
  248. }
  249. $shopId = $recharge->shopId ?? 0;
  250. $shopExt = ShopExtClass::getByCondition(['shopId' => $shopId], true);
  251. if (!empty($shopExt->lbSn)) {
  252. $actPrice = $recharge->amount ?? 0;
  253. $payWay = $recharge->payWay ?? 0;
  254. $sound = $payWay == 0 ? "微信充值{$actPrice}元," : "支付宝充值{$actPrice}元";
  255. $url = "https://speaker.17laimai.cn/notify.php?id={$shopExt->lbSn}&token=HK1626595800&version={$shopExt->lbVersion}&message=" . $sound;
  256. $curl = new curl\Curl();
  257. $curl->get($url);
  258. }
  259. }
  260. public static function hdScanPayReport($order)
  261. {
  262. if (empty($order)) {
  263. return false;
  264. }
  265. if ($order->payStatus != 1) {
  266. //还没有付款订单不播报
  267. return false;
  268. }
  269. $shopId = $order->shopId ?? 0;
  270. $shopExt = ShopExtClass::getByCondition(['shopId' => $shopId], true);
  271. if (!empty($shopExt->lbSn)) {
  272. $actPrice = $order->actPrice ?? 0;
  273. $payWay = $order->payWay ?? 0;
  274. $sound = $payWay == 0 ? "微信收款{$actPrice}元,谢谢惠顾,欢迎下次光临" : "支付宝收款{$actPrice}元,谢谢惠顾,欢迎下次光临";
  275. $url = "https://speaker.17laimai.cn/notify.php?id={$shopExt->lbSn}&token=HK1626595800&version={$shopExt->lbVersion}&message=" . $sound;
  276. $curl = new curl\Curl();
  277. $curl->get($url);
  278. }
  279. }
  280. /**
  281. * 供货商收款声音播放
  282. * 职责:向外部音箱接口发送语音播报请求,提示商户收款成功
  283. * 入参:ActiveRecord $order (订单模型实例)
  284. * 返回:bool (是否成功触发播报)
  285. * 副作用:发送外部 HTTP 网络请求
  286. * 关键边界:
  287. * 1. 仅限门店订单、在线支付且已付款的订单播报
  288. * 2. 优化:设置极短的 cURL 连接超时与执行超时限制,并强制使用 IPv4 解析,防止因外部音箱接口延迟拖垮收银支付主流程
  289. */
  290. public static function ghsGatheringReport($order)
  291. {
  292. if ($order->fromType != dict::getDict("fromType", "shop")) {
  293. //非门店订单不播报语音
  294. return false;
  295. }
  296. if ($order->onlinePay == dict::getDict('onlinePay', 'not')) {
  297. //非在线支付的不播报
  298. return false;
  299. }
  300. if ($order->payStatus != 1) {
  301. //还没有付款订单不播报
  302. return false;
  303. }
  304. $shopId = $order->shopId ?? 0;
  305. $shopExt = ShopExtClass::getByCondition(['shopId' => $shopId], true);
  306. if (isset($shopExt->lbSn) && !empty($shopExt->lbSn)) {
  307. $actPrice = $order->actPrice ? floatval($order->actPrice) : 0;
  308. $payWay = $order->payWay ?? dict::getDict('payWay', 'wxPay');
  309. $sound = $payWay == dict::getDict('payWay', 'wxPay') ? "微信收款{$actPrice}元,谢谢惠顾,欢迎下次光临" : "支付宝收款{$actPrice}元,谢谢惠顾,欢迎下次光临";
  310. $url = "https://speaker.17laimai.cn/notify.php?id={$shopExt->lbSn}&token=HK1626595800&version={$shopExt->lbVersion}&message=" . $sound;
  311. $curl = new curl\Curl();
  312. // 复杂分支/关键逻辑:设置 cURL 连接和执行超时,并强制使用 IPv4,防止因外部音箱接口卡顿或 DNS 解析慢拖垮收银结账主进程
  313. $curl->setOption(CURLOPT_CONNECTTIMEOUT, 1); // 连接超时限制为 1 秒,避免网络握手长时间卡死
  314. $curl->setOption(CURLOPT_TIMEOUT, 1); // 总执行时间限制为 1 秒,避免请求挂起时间过长
  315. $curl->setOption(CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); // 强制 IPv4 解析,防止 IPv6 解析超时重试
  316. $curl->get($url);
  317. }
  318. }
  319. //订单取消,钱原路退回,提醒客户
  320. public static function orderCancelBackMoneyReport($shopId)
  321. {
  322. $shopExt = ShopExtClass::getByCondition(['shopId' => $shopId], true);
  323. if (!empty($shopExt->lbSn)) {
  324. $sound = "订单已取消,付款已原路退回,请稍等几秒重新付款";
  325. $url = "https://speaker.17laimai.cn/notify.php?id={$shopExt->lbSn}&token=HK1626595800&version={$shopExt->lbVersion}&message=" . $sound;
  326. $curl = new curl\Curl();
  327. $curl->get($url);
  328. }
  329. }
  330. //提醒输入密码 ssh 20250501
  331. public static function remindInputPassword($shopId)
  332. {
  333. $shopExt = ShopExtClass::getByCondition(['shopId' => $shopId], true);
  334. if (!empty($shopExt->lbSn)) {
  335. $sound = "请输入密码";
  336. $url = "https://speaker.17laimai.cn/notify.php?id={$shopExt->lbSn}&token=HK1626595800&version={$shopExt->lbVersion}&message=" . $sound;
  337. $curl = new curl\Curl();
  338. $curl->get($url);
  339. }
  340. }
  341. //清除所有小菊
  342. public static function clearXjALl($shopId)
  343. {
  344. $where = [];
  345. $where['shopId'] = $shopId;
  346. return self::updateByCondition($where, ['xj' => '']);
  347. }
  348. }