NoticeClass.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. <?php
  2. namespace bizHd\notice\classes;
  3. use biz\base\classes\BaseClass;
  4. use bizHd\admin\classes\AdminClass;
  5. use bizHd\purchase\classes\PurchaseClass;
  6. use bizHd\staff\classes\StaffClass;
  7. use bizHd\wx\classes\WxOpenClass;
  8. use common\components\dict;
  9. use common\components\miniUtil;
  10. use Yii;
  11. class NoticeClass extends BaseClass
  12. {
  13. //售后结果通知 ssh 20230813
  14. public static function afterSaleNotice($shop, $refund)
  15. {
  16. $result = [];
  17. $mainId = $shop->mainId ?? 0;
  18. $staffList = StaffClass::getAllByCondition(['mainId' => $mainId], null, 'adminId');
  19. $merchant = WxOpenClass::getWxInfo();
  20. $ptStyle = dict::getDict('ptStyle', 'hd');
  21. if (getenv('YII_ENV') == 'production') {
  22. $msgList = dict::getDict('hdMiniMessage');
  23. } else {
  24. $msgList = dict::getDict('hdMiniMessageDev');
  25. }
  26. $msgId = $msgList['afterSale']['msgId'] ?? '';
  27. if (empty($msgId)) {
  28. return $result;
  29. }
  30. if (!empty($staffList)) {
  31. $ids = array_column($staffList, 'adminId');
  32. if (!empty($ids)) {
  33. $adminList = AdminClass::getByIds($ids);
  34. if (!empty($adminList)) {
  35. $orderSn = $refund->orderSn ?? '';
  36. $refundType = $refund->refundType ?? 1;
  37. $name = $refundType == 1 ? '退货退款' : '只退款';
  38. $addTime = $refund->addTime ?? '';
  39. $status = $refund->status ?? 0;
  40. $statusName = '已通过';
  41. if ($status == 2) {
  42. $statusName = '已驳回';
  43. }
  44. foreach ($adminList as $admin) {
  45. $miniOpenId = $admin['miniOpenId'] ?? '';
  46. if (!empty($miniOpenId)) {
  47. $msg = [
  48. "thing4" => ["value" => $name],
  49. "time5" => ["value" => $addTime],
  50. "character_string3" => ["value" => $orderSn],
  51. "phrase2" => ["value" => $statusName],
  52. "thing6" => ["value" => "点击查看详情"],
  53. ];
  54. $page = 'pagesPurchase/refundDetail?id=' . $refund->id;
  55. Yii::info(json_encode($msg));
  56. $respond = miniUtil::commonSendSubscribeMessage($merchant, $ptStyle, $msgId, $miniOpenId, $page, $msg);
  57. if (isset($respond['errcode']) && $respond['errcode'] === 0) {
  58. $result['hasNotice'] = 1;
  59. }
  60. }
  61. }
  62. }
  63. }
  64. }
  65. return $result;
  66. }
  67. //有新的结账单 ssh 20230514
  68. public static function newClearNotice($shop, $clear)
  69. {
  70. $result = [];
  71. $mainId = $shop->mainId ?? 0;
  72. $staffList = StaffClass::getAllByCondition(['mainId' => $mainId], null, 'adminId');
  73. $merchant = WxOpenClass::getWxInfo();
  74. $ptStyle = dict::getDict('ptStyle', 'hd');
  75. if (getenv('YII_ENV') == 'production') {
  76. $msgList = dict::getDict('hdMiniMessage');
  77. } else {
  78. $msgList = dict::getDict('hdMiniMessageDev');
  79. }
  80. $msgId = $msgList['remindHdClear']['msgId'] ?? '';
  81. if (empty($msgId)) {
  82. return $result;
  83. }
  84. $num = $clear->num ?? 0;
  85. $actPrice = $clear->actPrice ?? 0;
  86. $ghsName = $clear->ghsName ?? '没有';
  87. if (!empty($staffList)) {
  88. $ids = array_column($staffList, 'adminId');
  89. if (!empty($ids)) {
  90. $adminList = AdminClass::getByIds($ids);
  91. if (!empty($adminList)) {
  92. foreach ($adminList as $admin) {
  93. $miniOpenId = $admin['miniOpenId'] ?? '';
  94. if (!empty($miniOpenId)) {
  95. $msg = [
  96. "thing5" => ["value" => $ghsName],
  97. "short_thing2" => ["value" => $num . "笔"],
  98. "amount3" => ["value" => $actPrice],
  99. "thing4" => ["value" => "点击帮我结下款哦"],
  100. ];
  101. $page = 'admin/clear/info?id=' . $clear->id;
  102. Yii::info(json_encode($msg));
  103. $respond = miniUtil::commonSendSubscribeMessage($merchant, $ptStyle, $msgId, $miniOpenId, $page, $msg);
  104. if (isset($respond['errcode']) && $respond['errcode'] === 0) {
  105. $result['hasNotice'] = 1;
  106. }
  107. }
  108. }
  109. }
  110. }
  111. }
  112. return $result;
  113. }
  114. //采购成功之后小程序通知
  115. public static function cgSuccessMiniNotice($cgShop, $cg)
  116. {
  117. $result = [];
  118. $mainId = $cgShop->mainId ?? 0;
  119. $staffList = StaffClass::getAllByCondition(['mainId' => $mainId], null, 'adminId');
  120. $merchant = WxOpenClass::getWxInfo();
  121. $ptStyle = dict::getDict('ptStyle', 'hd');
  122. if (getenv('YII_ENV') == 'production') {
  123. $msgList = dict::getDict('hdMiniMessage');
  124. } else {
  125. $msgList = dict::getDict('hdMiniMessageDev');
  126. }
  127. $msgId = $msgList['cgSuccess']['msgId'] ?? '';
  128. if (empty($msgId)) {
  129. return $result;
  130. }
  131. $ghsName = $cg->ghsName ?? '';
  132. $bigNum = $cg->bigNum ?? 0;
  133. $num = '';
  134. if ($bigNum > 0) {
  135. $num = $bigNum . '扎';
  136. }
  137. $smallNum = $cg->smallNum ?? 0;
  138. if ($smallNum > 0) {
  139. $num .= $smallNum . '支';
  140. }
  141. $name = "花材" . $num;
  142. $actPrice = $cg->actPrice ?? 0;
  143. $payTime = $cg->payTime ?? '';
  144. $remark = "点击查看详情";
  145. if (isset($cg->debt) && $cg->debt == 1) {
  146. $remark = "====点击付款====";
  147. $name = $name . '【赊账】';
  148. }
  149. if (!empty($staffList)) {
  150. $ids = array_column($staffList, 'adminId');
  151. if (!empty($ids)) {
  152. $adminList = AdminClass::getByIds($ids);
  153. if (!empty($adminList)) {
  154. foreach ($adminList as $admin) {
  155. $miniOpenId = $admin['miniOpenId'] ?? '';
  156. if (!empty($miniOpenId)) {
  157. $msg = [
  158. "thing1" => ["value" => $ghsName],
  159. "thing2" => ["value" => $name],
  160. "amount3" => ["value" => $actPrice],
  161. "date4" => ["value" => $payTime],
  162. "thing5" => ["value" => $remark]
  163. ];
  164. $page = 'pagesPurchase/purDetails?id=' . $cg->id;
  165. $respond = miniUtil::commonSendSubscribeMessage($merchant, $ptStyle, $msgId, $miniOpenId, $page, $msg);
  166. if (isset($respond['errcode']) && $respond['errcode'] === 0) {
  167. $result['hasNotice'] = 1;
  168. }
  169. }
  170. }
  171. }
  172. }
  173. }
  174. return $result;
  175. }
  176. //订单发货后小程序通知
  177. public static function orderFhMiniNotice($order)
  178. {
  179. $cgId = $order->purchaseId ?? 0;
  180. $cg = PurchaseClass::getById($cgId, true);
  181. if (empty($cg)) {
  182. return false;
  183. }
  184. $result = [];
  185. $mainId = $cg->mainId ?? 0;
  186. $staffList = StaffClass::getAllByCondition(['mainId' => $mainId], null, 'adminId');
  187. $merchant = WxOpenClass::getWxInfo();
  188. $ptStyle = dict::getDict('ptStyle', 'hd');
  189. if (getenv('YII_ENV') == 'production') {
  190. $msgList = dict::getDict('hdMiniMessage');
  191. } else {
  192. $msgList = dict::getDict('hdMiniMessageDev');
  193. }
  194. $msgId = $msgList['fhNotice']['msgId'] ?? '';
  195. if (empty($msgId)) {
  196. return $result;
  197. }
  198. $ghsName = $cg->ghsName ?? '';
  199. $bigNum = $cg->bigNum ?? 0;
  200. $num = '';
  201. if ($bigNum > 0) {
  202. $num = $bigNum . '扎';
  203. }
  204. $smallNum = $cg->smallNum ?? 0;
  205. if ($smallNum > 0) {
  206. $num .= $smallNum . '支';
  207. }
  208. $name = "花材" . $num;
  209. $orderSn = $cg->orderSn ?? '';
  210. $sendTime = date("Y-m-d H:i:s");
  211. $remark = "点击查看详情";
  212. if (isset($cg->debt) && $cg->debt == 1) {
  213. $remark = "===点击查看详情===";
  214. }
  215. if (!empty($staffList)) {
  216. $ids = array_column($staffList, 'adminId');
  217. if (!empty($ids)) {
  218. $adminList = AdminClass::getByIds($ids);
  219. if (!empty($adminList)) {
  220. foreach ($adminList as $admin) {
  221. $miniOpenId = $admin['miniOpenId'] ?? '';
  222. if (!empty($miniOpenId)) {
  223. $msg = [
  224. "thing12" => ["value" => $ghsName],
  225. "thing1" => ["value" => $name],
  226. "character_string2" => ["value" => $orderSn],
  227. "date3" => ["value" => $sendTime],
  228. "thing6" => ["value" => $remark]
  229. ];
  230. $page = 'pagesPurchase/purDetails?id=' . $cg->id;
  231. $respond = miniUtil::commonSendSubscribeMessage($merchant, $ptStyle, $msgId, $miniOpenId, $page, $msg);
  232. if (isset($respond['errcode']) && $respond['errcode'] === 0) {
  233. $result['hasNotice'] = 1;
  234. }
  235. }
  236. }
  237. }
  238. }
  239. }
  240. return $result;
  241. }
  242. }