Model_notice.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. class Model_notice extends Lin_Model
  3. {
  4. function __construct(){
  5. parent::__construct();
  6. $this->load->database();
  7. $this->table = 'notice';
  8. $this->load_table('notice');
  9. $this->load->_model("Model_logic_ding","logic_ding");
  10. $this->load->_model("Model_sdzxlist","sdzxlist");
  11. }
  12. public function get_type($shop,$type,$logisticstatus,$ordertatus)//查找符合消息发送条件的信息
  13. {
  14. if($type == 1)
  15. {
  16. return $this->find("shop = '$shop' and type = '$type' and ordertatus = '$ordertatus' and state = 1 and ktime < 'time()' and jtime < 'time()'");
  17. }
  18. else if($type == 2)
  19. {
  20. return $this->find("shop = '$shop' and type = '$type' and logisticstatus = '$logisticstatus' and state = 1 and ktime < 'time()' and jtime < 'time()'");
  21. }
  22. else if($type == 3)
  23. {
  24. return $this->find("shop = '$shop' and type = '$type' and state = 1 and ktime < 'time()' and jtime < 'time()'");
  25. }
  26. }
  27. //所属店铺、模板类型、物流状态/订单状态
  28. /** 通过订单状态 */
  29. public function get_ordertatus($ordertatus)
  30. {
  31. return $this->find("ordertatus = '$ordertatus'");
  32. }
  33. public function get_go($list,$shop,$genre,$option)
  34. {
  35. //aptsmt获取订单:崔付款、确认地址
  36. $time = time();
  37. $data = $this->find("shop = '".$shop['id']."' and ".$genre." = '$option' and ktime < '$time' and jtime > '$time' and state = 1");//$genre三种模式:订单状态、物流跟踪、营销。启用状态下,有效期内搜索该店铺设置
  38. if($data)//如果可用模板配置
  39. {
  40. $message=2;
  41. $list['orderinfo'] = ($message==1)?substr($list['orderinfo'],1):$list['orderinfo'];
  42. if($message==1)
  43. {
  44. $expresscode = (isset($express['title']))?$express['title']:'';
  45. }
  46. else
  47. {
  48. $expresscode = (isset($express['aecode']))?$express['aecode']:'';
  49. }
  50. if(!isset($list['country']))
  51. {
  52. $list['waybill'] = '';
  53. $list['phone'] = '';
  54. $list['zipcode'] = '';
  55. $list['country'] = '';
  56. $list['province'] = '';
  57. $list['city'] = '';
  58. $list['address'] = '';
  59. $list['product'] = '';
  60. }
  61. $express['url'] = (isset($express['url']))?$express['url']:'';
  62. $list['userName'] = (isset($list['userName']))?$list['userName']:'';
  63. $list['orderid'] = (isset($list['orderid']))?$list['orderid']:'';
  64. $list['name'] = (isset($list['name']))?$list['name']:'';
  65. $list['bname'] = (isset($list['bname']))?$list['bname']:'';
  66. $list['sname'] = (isset($list['sname']))?$list['sname']:'';
  67. $list['saddress'] = (isset($list['saddress']))?$list['saddress']:'';
  68. $list['baddress'] = (isset($list['baddress']))?$list['baddress']:'';
  69. $list['quantity'] = (isset($list['quantity']))?(($list['quantity'] > '1')?$list['quantity'].' packages of':''):'';
  70. $list['parameter'] = (isset($list['parameter']))?$list['parameter']:'';
  71. $ProductSKU = (isset($list['issku']))?$list['issku']:$list['sku'];
  72. $yjtime = (isset($express['yjtime']))?$express['yjtime']:'';
  73. $product = '';
  74. if($list['product'] != '')
  75. {
  76. $list['product'] = str_replace("'","",$list['product']);
  77. if($list['link'] != '' && $list['source'] != '1')
  78. {
  79. $pt = explode(',',$list['product']);
  80. $lk = explode(',',$list['link']);
  81. for($i=0;$i<count($pt);$i++)
  82. {
  83. $a = $pt[$i];
  84. //$a = (stripos($pt[$i],'Lace Front Wig Body Wave Human Hair Wigs Pre Plucked Brazilian Virgin Hair') !== false || stripos($pt[$i],'Deep Wave Wig 100 Human Hair Swiss Lace Curly Hair Lace Front Wig') !== false || stripos($pt[$i],'Alipearl Lace Front Wig Silky Straight 100% Virgin Human Hair') !== false || stripos($pt[$i],'Long Wigs Water Wave Lace Front Wigs Natural Wave Wigs For Sale') !== false || stripos($pt[$i],'Deep Wave Long Hair Wigs Lace Front Wigs Cheap Human Hair Wigs') !== false || stripos($pt[$i],'Long Wigs Loose Deep Wave Lace Front Wigs For Black Women') !== false || stripos($pt[$i],'Long Black Wigs Body Wave Lace Front Wigs With Baby Hair') !== false || stripos($pt[$i],'Long Curly Wigs Lace Front Wigs Human Hair Lace Front Wigs') !== false || stripos($pt[$i],'Blonde Skunk Stripe Hair Natural Body Wave Hairstyle Lace Wigs for Women') !== false)?'<font style="color:#F39">'.$pt[$i].'</font>':$pt[$i];
  85. if(isset($lk[$i]) && isset($content) && stripos($content,'<img') !== false)
  86. {
  87. $product .= ($product != '')?' , <a href="'.$lk[$i].'" target="_blank">'.$a.'</a>':'<a href="'.$lk[$i].'" target="_blank">'.$a.'</a>';
  88. }
  89. else
  90. {
  91. $product .= ($product != '')?' , '.$a:$a;
  92. }
  93. }
  94. }
  95. }
  96. $ProductName = '';
  97. $st = explode(';',trim($list['fpdata'],';'));
  98. foreach ($st as $v)
  99. {
  100. $v = explode('|',trim($v,'|'));
  101. $th = $this->producttitle->get_title($v[1]);
  102. if($th)
  103. {
  104. $ProductName .= $th['th'].', ';
  105. }
  106. else
  107. {
  108. $ProductName .= $v[1].', ';
  109. }
  110. }
  111. $ProductName = trim($ProductName,', ');
  112. $firstName = explode(' ',$list['name']);
  113. $t= array('$userName','$firstName','$orderid','$trackingNumber','$expressCompany','$expressWebsite','$contactPerson','$Bname','$Sname','$mobileNo','$zip','$country','$province','$city','$recipientAddress','$productInfo','$ShipAddress','$BillAddress','$Quantity','$parameter','$productTitle','$ProductName','$ProductSKU','$DeliveryTime',"[Smile]","[Shy]","[Tongue]","[Titter]","[Admire]","[Risus]","[Dance]","[Blow a Kiss]","[Comfort]","[Hug]","[Put on steam]","[Victory]","[Strong]","[Kiss]","[Anthomaniac]","[Grin]","[Seek]","[Call out]","[Cast accounts]","[Miser]","[Good idea]","[Grimace]","[Angel]","[Good bye]","[Drool]","[Enjoy]","[Erotomania]","[Dumbstruck]","[Thinking]","[Puzzle]","[Query]","[No money]","[Bored]","[Suspect]","[Hush]","[Complacent]","[Shake head]","[Cold]","[Awkward]","[Smirk]","[Amazed]","[However]","[Sweat]","[Loneliness]","[Sleepy]","[Faint]","[Distressed]","[Grievance]","[Sob]","[Cry]","[Wail]","[Obey]","[Sorry]","[Bye]","[Frown]","[So tired]","[Fall ill]","[Vomit]","[Fall on evil days]","[Surprised]","[Stunned]","[Shut up]","[Due to flat]","[Despise you]","[Rage]","[Angry]","[Mammon]","[Learn from lei feng]","[Wishing you prosperity]","[Waiter]","[Boss]","[Evil]","[Challenge]","[CS]","[Invisible man]","[Bomb]","[Scream]","[Beautiful girl]","[Handsome boy]","[Fortune cat]","[Deal]","[Handclap]","[Handshake]","[Lips]","[Rose]","[Wither]","[Heart]","[Heartbreak]","[Money]","[Shopping]","[Gift]","[Email]","[Phone]","[Cheers]","[Clock]","[Waiting]","[Late]","[Plane]","[Alipay]");//需要被替换的内容
  114. $h= array($list['name'],$firstName,$list['orderinfo'],$list['waybill'],$expresscode,$express['url'],$list['name'],$list['bname'],$list['sname'],$list['phone'],$list['zipcode'],$list['country'],$list['province'],$list['city'],$list['address'],$list['product'],$list['saddress'],$list['baddress'],$list['quantity'],$list['parameter'],$product,$ProductName,$ProductSKU,$yjtime,"/:000","/:001","/:002","/:003","/:004","/:005","/:006","/:007","/:008","/:009","/:010","/:011","/:012","/:013","/:014","/:015","/:016","/:017","/:018","/:019","/:020","/:021","/:022","/:023","/:024","/:025","/:026","/:027","/:028","/:029","/:030","/:031","/:032","/:033","/:034","/:035","/:036","/:037","/:038","/:039","/:040","/:041","/:042","/:043","/:044","/:045","/:046","/:047","/:048","/:049","/:050","/:051","/:052","/:053","/:054","/:055","/:056","/:057","/:058","/:059","/:060","/:061","/:062","/:063","/:064","/:065","/:066","/:067","/:068","/:069","/:070","/:071","/:072","/:073","/:074","/:075","/:076","/:077","/:078","/:079","/:080","/:081","/:082","/:083","/:084","/:085","/:086","/:087","/:088","/:089","/:090","/:091","/:092","/:093","/:094","/:095","/:096","/:097","/:098");//替换的内容
  115. $content = str_replace($t,$h,$data['content']);
  116. if($data['message'] == 1)//如果是发送邮件
  117. {
  118. if(!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$list['email']))
  119. {
  120. return '邮箱地址错误,请检查';exit;
  121. }
  122. $emailbt = ($data['emailtitle'] != '')?str_replace($t,$h,$data['emailtitle']):'The product you purchased has a new progress';
  123. $this->load->library('email');
  124. $config['protocol'] = 'smtp';
  125. $config['smtp_host'] = 'smtpdm-ap-southeast-1.aliyun.com';
  126. $config['smtp_port'] = 465;
  127. $config['smtp_user'] = 'service@email.supernovahair.com';
  128. $config['smtp_pass'] = 'LONGyihair374';
  129. $config['smtp_crypto'] = 'ssl';
  130. $config['crlf'] = "\r\n";
  131. $config['newline'] = "\r\n";
  132. $this->email->initialize($config);
  133. $this->email->set_newline("\r\n");
  134. $this->email->from('service@email.supernovahair.com',$shopname);
  135. $this->email->to($list['email']);//收件
  136. $this->email->subject($emailbt);//标题
  137. $this->email->message($content);//内容
  138. if ($this->email->send())
  139. {
  140. return 1;//成功
  141. }
  142. else
  143. {
  144. return '发送失败';
  145. }
  146. }
  147. else if($data['message'] == 2 && $list['userid'] != '')//如果是速卖通站内信,用户ID不为空
  148. {
  149. $ch = curl_init();
  150. $url = 'http://39.100.97.180/smtold.php';
  151. curl_setopt($ch,CURLOPT_URL,$url);
  152. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  153. curl_setopt($ch,CURLOPT_HEADER,0);
  154. curl_setopt($ch,CURLOPT_POST, 1);
  155. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,600);
  156. //设置post数据
  157. $post = array();
  158. $post['shopid'] = $shop['brandname'];//速卖通店铺ID
  159. $post['userid'] = $list['userid'];//速卖通买家ID
  160. $post['message_type'] = 'order';//消息类型,product(商品)、member(会员,包含店铺)、order(订单)
  161. $post['content'] = $content;//发送内容
  162. $post['code'] = $shop['code'];
  163. $post['order'] = $list['orderinfo'];
  164. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  165. $res = curl_exec($ch);
  166. curl_close($ch);
  167. $res = json_decode($res,true);
  168. if(isset($res['is_success']))
  169. {
  170. return 1;//成功
  171. }
  172. else
  173. {
  174. return isset($res['error_msg'])?$res['error_msg']:(isset($res['sub_msg'])?$res['sub_msg']:'发送失败');
  175. }
  176. }
  177. else
  178. {
  179. return '邮箱错误或者没有UserID';
  180. }
  181. }
  182. else
  183. {
  184. return '无可用站内信模板';
  185. }
  186. }
  187. public function get_god($list,$shop,$express,$notice)//单个订单整体模式
  188. {
  189. if( isset($shop['id']) && ($shop['id'] == 5)){
  190. //暂时不写井号 避免出问题
  191. $list['orderinfo'] = substr($list['orderinfo'],1);
  192. }else{
  193. $list['orderinfo'] = ($notice['message']==1)?substr($list['orderinfo'],1):$list['orderinfo'];
  194. }
  195. if($notice['message']==1)
  196. {
  197. $expresscode = (isset($express['title']))?$express['title']:'';
  198. }
  199. else
  200. {
  201. $expresscode = (isset($express['aecode']))?$express['aecode']:'';
  202. }
  203. if(!isset($list['country']))
  204. {
  205. $list['waybill'] = '';
  206. $list['phone'] = '';
  207. $list['zipcode'] = '';
  208. $list['country'] = '';
  209. $list['province'] = '';
  210. $list['city'] = '';
  211. $list['address'] = '';
  212. $list['product'] = '';
  213. }
  214. $express['url'] = (isset($express['url']))?$express['url']:'';
  215. $list['userName'] = (isset($list['userName']))?$list['userName']:'';
  216. $list['orderid'] = (isset($list['orderid']))?$list['orderid']:'';
  217. $list['name'] = (isset($list['name']))?$list['name']:'';
  218. $list['bname'] = (isset($list['bname']))?$list['bname']:'';
  219. $list['sname'] = (isset($list['sname']))?$list['sname']:'';
  220. $list['saddress'] = (isset($list['saddress']))?$list['saddress']:'';
  221. $list['baddress'] = (isset($list['baddress']))?$list['baddress']:'';
  222. $list['quantity'] = (isset($list['quantity']))?(($list['quantity'] > '1')?$list['quantity'].' packages of':''):'';
  223. $list['parameter'] = (isset($list['parameter']))?$list['parameter']:'';
  224. $list['waybill'] = (isset($list['waybill']))?$list['waybill']:'';
  225. //$ProductSKU = (isset($list['issku']))?$list['issku']:$list['sku'];
  226. $ProductSKU = "";
  227. if(isset($list['issku'])){
  228. $ProductSKU = $list['issku'];
  229. }else{
  230. if(isset($list['sku'])){
  231. $ProductSKU = $list['sku'];
  232. }
  233. }
  234. $yjtime = (isset($express['yjtime']))?$express['yjtime']:'';
  235. $product = '';
  236. if($list['product'] != '')
  237. {
  238. $list['product'] = str_replace("'","",$list['product']);
  239. if($list['link'] != '' && $list['source'] != '1')
  240. {
  241. $pt = explode(',',$list['product']);
  242. $lk = explode(',',$list['link']);
  243. for($i=0;$i<count($pt);$i++)
  244. {
  245. $a = $pt[$i];
  246. //$a = (stripos($pt[$i],'Lace Front Wig Body Wave Human Hair Wigs Pre Plucked Brazilian Virgin Hair') !== false || stripos($pt[$i],'Deep Wave Wig 100 Human Hair Swiss Lace Curly Hair Lace Front Wig') !== false || stripos($pt[$i],'Alipearl Lace Front Wig Silky Straight 100% Virgin Human Hair') !== false || stripos($pt[$i],'Long Wigs Water Wave Lace Front Wigs Natural Wave Wigs For Sale') !== false || stripos($pt[$i],'Deep Wave Long Hair Wigs Lace Front Wigs Cheap Human Hair Wigs') !== false || stripos($pt[$i],'Long Wigs Loose Deep Wave Lace Front Wigs For Black Women') !== false || stripos($pt[$i],'Long Black Wigs Body Wave Lace Front Wigs With Baby Hair') !== false || stripos($pt[$i],'Long Curly Wigs Lace Front Wigs Human Hair Lace Front Wigs') !== false || stripos($pt[$i],'Blonde Skunk Stripe Hair Natural Body Wave Hairstyle Lace Wigs for Women') !== false)?'<font style="color:#F39">'.$pt[$i].'</font>':$pt[$i];
  247. if(isset($lk[$i]) && stripos($notice['content'],'<img') !== false)
  248. {
  249. $product .= ($product != '')?' , <a href="'.$lk[$i].'" target="_blank">'.$a.'</a>':'<a href="'.$lk[$i].'" target="_blank">'.$a.'</a>';
  250. }
  251. else
  252. {
  253. $product .= ($product != '')?' , '.$a:$a;
  254. }
  255. }
  256. }else{
  257. if(isset($shop['id']) && ($shop['id'] == 5) && $list['source'] != '1'){
  258. $pt = explode(',',$list['product']);
  259. $lk = explode(',',$list['link']);
  260. for($i=0;$i<count($pt);$i++)
  261. {
  262. $a = $pt[$i];
  263. //$a = (stripos($pt[$i],'Lace Front Wig Body Wave Human Hair Wigs Pre Plucked Brazilian Virgin Hair') !== false || stripos($pt[$i],'Deep Wave Wig 100 Human Hair Swiss Lace Curly Hair Lace Front Wig') !== false || stripos($pt[$i],'Alipearl Lace Front Wig Silky Straight 100% Virgin Human Hair') !== false || stripos($pt[$i],'Long Wigs Water Wave Lace Front Wigs Natural Wave Wigs For Sale') !== false || stripos($pt[$i],'Deep Wave Long Hair Wigs Lace Front Wigs Cheap Human Hair Wigs') !== false || stripos($pt[$i],'Long Wigs Loose Deep Wave Lace Front Wigs For Black Women') !== false || stripos($pt[$i],'Long Black Wigs Body Wave Lace Front Wigs With Baby Hair') !== false || stripos($pt[$i],'Long Curly Wigs Lace Front Wigs Human Hair Lace Front Wigs') !== false || stripos($pt[$i],'Blonde Skunk Stripe Hair Natural Body Wave Hairstyle Lace Wigs for Women') !== false)?'<font style="color:#F39">'.$pt[$i].'</font>':$pt[$i];
  264. if(isset($lk[$i]) && stripos($notice['content'],'<img') !== false)
  265. {
  266. $product .= ($product != '')?' , <a href="'.$lk[$i].'" target="_blank">'.$a.'</a>':'<a href="'.$lk[$i].'" target="_blank">'.$a.'</a>';
  267. }
  268. else
  269. {
  270. $product .= ($product != '')?' , '.$a:$a;
  271. }
  272. }
  273. }
  274. }
  275. }
  276. //$this->logic_ding->sendToDing("监听同步平台信息".$list['orderinfo']."的product【".$list['product']."】以及对应的pt:【".json_encode($pt)."】最终生成的product".$product);
  277. if(empty($data['fpdata'])){
  278. // $this->logic_ding->sendToDing("监听同步平台信息缺失fpdata".$list['orderinfo']."的传递的信息【".json_encode($list)."】");
  279. }
  280. $ProductName = '';
  281. if(empty($list['fpdata'])){
  282. $st = [];
  283. }else{
  284. $st = explode(';',trim($list['fpdata'],';'));
  285. }
  286. foreach ($st as $v)
  287. {
  288. $v = explode('|',trim($v,'|'));
  289. if(isset($v[1]))
  290. {
  291. $th = $this->producttitle->get_title($v[1]);
  292. if($th)
  293. {
  294. $ProductName .= $th['th'].', ';
  295. }
  296. else
  297. {
  298. $ProductName .= $v[1].', ';
  299. }
  300. }
  301. }
  302. $ProductName = trim($ProductName,', ');
  303. $firstName = explode(' ',$list['name']);
  304. $t= array('$userName','$firstName','$orderid','$trackingNumber','$expressCompany','$expressWebsite','$contactPerson','$Bname','$Sname','$mobileNo','$zip','$country','$province','$city','$recipientAddress','$productInfo','$ShipAddress','$BillAddress','$Quantity','$parameter','$productTitle','$ProductName','$ProductSKU','$DeliveryTime',"[Smile]","[Shy]","[Tongue]","[Titter]","[Admire]","[Risus]","[Dance]","[Blow a Kiss]","[Comfort]","[Hug]","[Put on steam]","[Victory]","[Strong]","[Kiss]","[Anthomaniac]","[Grin]","[Seek]","[Call out]","[Cast accounts]","[Miser]","[Good idea]","[Grimace]","[Angel]","[Good bye]","[Drool]","[Enjoy]","[Erotomania]","[Dumbstruck]","[Thinking]","[Puzzle]","[Query]","[No money]","[Bored]","[Suspect]","[Hush]","[Complacent]","[Shake head]","[Cold]","[Awkward]","[Smirk]","[Amazed]","[However]","[Sweat]","[Loneliness]","[Sleepy]","[Faint]","[Distressed]","[Grievance]","[Sob]","[Cry]","[Wail]","[Obey]","[Sorry]","[Bye]","[Frown]","[So tired]","[Fall ill]","[Vomit]","[Fall on evil days]","[Surprised]","[Stunned]","[Shut up]","[Due to flat]","[Despise you]","[Rage]","[Angry]","[Mammon]","[Learn from lei feng]","[Wishing you prosperity]","[Waiter]","[Boss]","[Evil]","[Challenge]","[CS]","[Invisible man]","[Bomb]","[Scream]","[Beautiful girl]","[Handsome boy]","[Fortune cat]","[Deal]","[Handclap]","[Handshake]","[Lips]","[Rose]","[Wither]","[Heart]","[Heartbreak]","[Money]","[Shopping]","[Gift]","[Email]","[Phone]","[Cheers]","[Clock]","[Waiting]","[Late]","[Plane]","[Alipay]");//需要被替换的内容
  305. $h= array($list['name'],$firstName[0],$list['orderinfo'],$list['waybill'],$expresscode,$express['url'],$list['name'],$list['bname'],$list['sname'],$list['phone'],$list['zipcode'],$list['country'],$list['province'],$list['city'],$list['address'],$list['product'],$list['saddress'],$list['baddress'],$list['quantity'],$list['parameter'],$product,$ProductName,$ProductSKU,$yjtime,"/:000","/:001","/:002","/:003","/:004","/:005","/:006","/:007","/:008","/:009","/:010","/:011","/:012","/:013","/:014","/:015","/:016","/:017","/:018","/:019","/:020","/:021","/:022","/:023","/:024","/:025","/:026","/:027","/:028","/:029","/:030","/:031","/:032","/:033","/:034","/:035","/:036","/:037","/:038","/:039","/:040","/:041","/:042","/:043","/:044","/:045","/:046","/:047","/:048","/:049","/:050","/:051","/:052","/:053","/:054","/:055","/:056","/:057","/:058","/:059","/:060","/:061","/:062","/:063","/:064","/:065","/:066","/:067","/:068","/:069","/:070","/:071","/:072","/:073","/:074","/:075","/:076","/:077","/:078","/:079","/:080","/:081","/:082","/:083","/:084","/:085","/:086","/:087","/:088","/:089","/:090","/:091","/:092","/:093","/:094","/:095","/:096","/:097","/:098");//替换的内容
  306. $notice['content'] = str_replace($t,$h,$notice['content']);
  307. $this->logic_ding->sendToDing("监听同步平台信息".$list['orderinfo']."【".$notice['content']."】");
  308. if($notice['emailtitle'] != '')
  309. {
  310. $notice['emailtitle'] = str_replace($t,$h,$notice['emailtitle']);
  311. $emailbt = $notice['emailtitle'];
  312. }
  313. else
  314. {
  315. $emailbt = $shop['brandname'].' Hair Service- Order Confirmation #'.$list['orderinfo'];
  316. }
  317. if($notice['message'] == 1)//如果是发送邮件
  318. {
  319. if(!$notice['email']['smtp_host'] || !$notice['email']['smtp_user'] || !$notice['email']['smtp_pass'])
  320. {
  321. return '此店铺没有配置邮件服务器信息!';exit;
  322. }
  323. if(!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$list['email']))
  324. {
  325. return '邮箱地址错误,请检查';exit;
  326. }
  327. if($notice['email']['smtp_host'] == 'smtp.gmail.com')
  328. {
  329. $ch = curl_init();
  330. $url = 'http://e.wepolicy.cn/';
  331. curl_setopt($ch,CURLOPT_URL,$url);
  332. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  333. curl_setopt($ch,CURLOPT_HEADER,0);
  334. curl_setopt($ch,CURLOPT_POST, 1);
  335. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,600);
  336. //设置post数据
  337. $post = array();
  338. $post['notice'] = $notice;
  339. $post['list'] = $list;
  340. $post['shop'] = $order;
  341. $post['emailbt'] = $emailbt;
  342. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  343. $res = curl_exec($ch);
  344. curl_close($ch);
  345. $res = json_decode($res,true);
  346. if($res)
  347. {
  348. return $res;//成功
  349. }
  350. else
  351. {
  352. return '发送失败';
  353. }
  354. }
  355. else
  356. {
  357. $this->load->library('email');
  358. $config['protocol'] = $notice['email']['protocol'];
  359. $config['smtp_host'] = $notice['email']['smtp_host'];
  360. $config['smtp_port'] = $notice['email']['smtp_port'];
  361. $config['smtp_timeout']='30';
  362. $config['smtp_user'] = $notice['email']['smtp_user'];
  363. $config['smtp_pass'] = $notice['email']['smtp_pass'];
  364. $config['smtp_crypto'] = $notice['email']['smtp_crypto'];
  365. $config['crlf'] = "\r\n";
  366. $config['newline'] = "\r\n";
  367. if(stripos($notice['content'],'</p>') !== false)
  368. {
  369. $notice['content'] = str_replace(array('<p>','<p style="'),array('<p style="margin:0px;">','<p style="margin:0px;'),$notice['content']);
  370. $config['mailtype'] = "html";
  371. }
  372. $this->email->initialize($config);
  373. $this->email->set_newline("\r\n");
  374. $this->email->from($notice['email']['smtp_user'],$shop['shopname']);//发送方
  375. $this->email->to($list['email']);//收件
  376. $this->email->subject($emailbt);//标题
  377. $this->email->message($notice['content']);//内容
  378. if ($this->email->send())
  379. {
  380. return 1;
  381. }
  382. else
  383. {
  384. return $this->email->print_debugger(array('headers'));
  385. }
  386. }
  387. }
  388. else if($notice['message'] == 2 && $list['userid'] != '')//如果是速卖通站内信,用户ID不为空
  389. {
  390. /**
  391. $ch = curl_init();
  392. $url = 'http://39.100.97.180/smtold.php';
  393. curl_setopt($ch,CURLOPT_URL,$url);
  394. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  395. curl_setopt($ch,CURLOPT_HEADER,0);
  396. curl_setopt($ch,CURLOPT_POST, 1);
  397. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,600);
  398. //设置post数据
  399. $post = array();
  400. $post['shopid'] = $shop['brandname'];//速卖通店铺ID
  401. $post['userid'] = $list['userid'];//速卖通买家ID
  402. $post['message_type'] = 'order';//消息类型,product(商品)、member(会员,包含店铺)、order(订单)
  403. $post['content'] = $notice['content'];//发送内容
  404. $post['code'] = $shop['code'];
  405. $post['order'] = $list['orderinfo'];
  406. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  407. $res = curl_exec($ch);
  408. curl_close($ch);
  409. $res = json_decode($res,true);
  410. if(isset($res['is_success']))
  411. {
  412. return 1;//成功
  413. }
  414. else
  415. {
  416. return $res;
  417. }
  418. **/
  419. }
  420. else if($notice['message'] == 3 && $list['user_id'] != '')//如果是TT会话,用户ID不为空
  421. {
  422. $url = 'https://open-api.tiktokglobalshop.com';
  423. $link = '/customer_service/202309/conversations';
  424. $time = time();
  425. $post['buyer_user_id'] = $list['user_id'];
  426. $queryParams['shop_cipher'] =$shop['shop_cipher'];
  427. //$queryParams['shop_id'] =$shop['codeid'];
  428. $queryParams['app_key'] =$shop['app_key'];
  429. $queryParams['timestamp'] =$time;
  430. $link .= '?'.http_build_query($queryParams);
  431. $sign = $this->apitt->sign($link,$shop['app_secret'],$post);
  432. $url .= $link.'&sign='.$sign;
  433. $headers = array('Content-Type: application/json','x-tts-access-token:'.$shop['token']);
  434. // $this->logic_ding->sendToDing('测试获取TT的请求参数'.json_encode([
  435. // 'post'=>$post,
  436. // 'queryParams'=>$queryParams,
  437. // 'content'=>$notice['content'],
  438. // 'shop'=>[
  439. // 'id'=>$shop['id'],
  440. // 'name'=>$shop['shopname']
  441. // ]
  442. // ],JSON_UNESCAPED_UNICODE));
  443. $res = $this->apitt->su_curl($post,$url,$headers);
  444. $res = json_decode($res,true);
  445. if(isset($res['data']['conversation_id']))
  446. {
  447. $f = $this->_ttfs($shop,$notice['content'],$res['data']['conversation_id']);
  448. $this->logic_ding->sendToDing('【'.$list['orderinfo'].'】TT发送信息结果回执成功'.json_encode($f,JSON_UNESCAPED_UNICODE));
  449. if(isset($f['data']['message_id']))
  450. {
  451. return 1;//成功
  452. }
  453. else
  454. {
  455. $this->sdzxlist->insert([
  456. 'type'=>1,
  457. 'status'=>0,
  458. 'shop'=>$shop['id'],
  459. 'number'=>$list['orderinfo'],
  460. 'cont'=>json_encode([
  461. 'post'=>$post,
  462. 'queryParams'=>$queryParams,
  463. 'content'=>$notice['content'],
  464. 'shop'=>[
  465. 'id'=>$shop['id'],
  466. 'name'=>$shop['shopname']
  467. ]
  468. ],JSON_UNESCAPED_UNICODE),
  469. 'err_desc'=>json_encode($res,JSON_UNESCAPED_UNICODE),
  470. 'create_time'=>time()
  471. ]);
  472. $this->logic_ding->sendJobs("tiktok_znx",[
  473. 'info'=>$list,
  474. 'content'=>$notice,
  475. 'shop'=>$shop
  476. ],5,'default');
  477. return isset($f['message'])?'B:'.$f['message']:'发送失败';
  478. }
  479. }
  480. else
  481. {
  482. $this->sdzxlist->insert([
  483. 'type'=>1,
  484. 'status'=>0,
  485. 'shop'=>$shop['id'],
  486. 'number'=>$list['orderinfo'],
  487. 'cont'=>json_encode([
  488. 'post'=>$post,
  489. 'queryParams'=>$queryParams,
  490. 'content'=>$notice['content'],
  491. 'shop'=>[
  492. 'id'=>$shop['id'],
  493. 'name'=>$shop['shopname']
  494. ]
  495. ],JSON_UNESCAPED_UNICODE),
  496. 'err_desc'=>json_encode($res,JSON_UNESCAPED_UNICODE),
  497. 'create_time'=>time()
  498. ]);
  499. $this->logic_ding->sendJobs("tiktok_znx",[
  500. 'info'=>$list,
  501. 'content'=>$notice,
  502. 'shop'=>$shop,
  503. ],5,'default');
  504. $this->logic_ding->sendToDing('【'.$list['orderinfo'].'】TT获取回话结果回执失败'.json_encode($res,JSON_UNESCAPED_UNICODE));
  505. return isset($res['message'])?'A:'.$res['message']:'发送失败';
  506. }
  507. }
  508. else
  509. {
  510. return '无可用发送平台!';
  511. }
  512. }
  513. public function _ttfs($shop,$notice,$conversation_id)//TT发送信息
  514. {
  515. $url = 'https://open-api.tiktokglobalshop.com';
  516. $link = '/customer_service/202309/conversations/'.$conversation_id.'/messages';
  517. $time = time();
  518. $notice = str_replace('</p>','\n',$notice);
  519. $post['type'] = 'TEXT';
  520. $post['content'] = '{"content": "'.strip_tags($notice).'"}';
  521. //$queryParams['access_token'] = $shop['token'];
  522. $queryParams['shop_cipher'] = $shop['shop_cipher'];
  523. $queryParams['shop_id'] = $shop['codeid'];
  524. $queryParams['app_key'] = $shop['app_key'];
  525. $queryParams['version'] = '202309';
  526. $queryParams['timestamp'] =$time;
  527. $link .= '?'.http_build_query($queryParams);
  528. $sign = $this->apitt->sign($link,$shop['app_secret'],$post);
  529. $url .= $link.'&sign='.$sign;
  530. $headers = array('Content-Type: application/json','x-tts-access-token:'.$shop['token']);
  531. $res = $this->apitt->su_curl($post,$url,$headers);
  532. $res = json_decode($res,true);
  533. return $res;
  534. }
  535. public function get_smtone($list,$shop,$content)//单个订单非快递信息模式模式
  536. {
  537. if(!isset($list['country']))
  538. {
  539. $list['waybill'] = '';
  540. $list['phone'] = '';
  541. $list['zipcode'] = '';
  542. $list['country'] = '';
  543. $list['province'] = '';
  544. $list['city'] = '';
  545. $list['address'] = '';
  546. $list['product'] = '';
  547. }
  548. $expresscode = (isset($express['aecode']))?$express['aecode']:'';
  549. $express['url'] = (isset($express['url']))?$express['url']:'';
  550. $list['userName'] = (isset($list['userName']))?$list['userName']:'';
  551. $list['orderid'] = (isset($list['orderid']))?$list['orderid']:'';
  552. $list['name'] = (isset($list['name']))?$list['name']:'';
  553. $list['bname'] = (isset($list['bname']))?$list['bname']:'';
  554. $list['sname'] = (isset($list['sname']))?$list['sname']:'';
  555. $product = '';
  556. if($list['product'] != '')
  557. {
  558. $list['product'] = str_replace("'","",$list['product']);
  559. if($list['link'] != '' && $list['source'] != '1')
  560. {
  561. $pt = explode(',',$list['product']);
  562. $lk = explode(',',$list['link']);
  563. for($i=0;$i<count($pt);$i++)
  564. {
  565. $a = $pt[$i];
  566. //$a = (stripos($pt[$i],'Lace Front Wig Body Wave Human Hair Wigs Pre Plucked Brazilian Virgin Hair') !== false || stripos($pt[$i],'Deep Wave Wig 100 Human Hair Swiss Lace Curly Hair Lace Front Wig') !== false || stripos($pt[$i],'Alipearl Lace Front Wig Silky Straight 100% Virgin Human Hair') !== false || stripos($pt[$i],'Long Wigs Water Wave Lace Front Wigs Natural Wave Wigs For Sale') !== false || stripos($pt[$i],'Deep Wave Long Hair Wigs Lace Front Wigs Cheap Human Hair Wigs') !== false || stripos($pt[$i],'Long Wigs Loose Deep Wave Lace Front Wigs For Black Women') !== false || stripos($pt[$i],'Long Black Wigs Body Wave Lace Front Wigs With Baby Hair') !== false || stripos($pt[$i],'Long Curly Wigs Lace Front Wigs Human Hair Lace Front Wigs') !== false || stripos($pt[$i],'Blonde Skunk Stripe Hair Natural Body Wave Hairstyle Lace Wigs for Women') !== false)?'<font style="color:#F39">'.$pt[$i].'</font>':$pt[$i];
  567. if(isset($lk[$i]) && stripos($content,'<img') !== false)
  568. {
  569. $product .= ($product != '')?' , <a href="'.$lk[$i].'" target="_blank">'.$a.'</a>':'<a href="'.$lk[$i].'" target="_blank">'.$a.'</a>';
  570. }
  571. else
  572. {
  573. $product .= ($product != '')?' , '.$a:$a;
  574. }
  575. }
  576. }
  577. }
  578. $firstName = explode(' ',$list['name']);
  579. $t= array('$userName','$firstName','$orderid','$trackingNumber','$expressCompany','$expressWebsite','$contactPerson','$Bname','$Sname','$mobileNo','$zip','$country','$province','$city','$recipientAddress','$productInfo','$ShipAddress','$BillAddress','$Quantity','$parameter','$productTitle',"[Smile]","[Shy]","[Tongue]","[Titter]","[Admire]","[Risus]","[Dance]","[Blow a Kiss]","[Comfort]","[Hug]","[Put on steam]","[Victory]","[Strong]","[Kiss]","[Anthomaniac]","[Grin]","[Seek]","[Call out]","[Cast accounts]","[Miser]","[Good idea]","[Grimace]","[Angel]","[Good bye]","[Drool]","[Enjoy]","[Erotomania]","[Dumbstruck]","[Thinking]","[Puzzle]","[Query]","[No money]","[Bored]","[Suspect]","[Hush]","[Complacent]","[Shake head]","[Cold]","[Awkward]","[Smirk]","[Amazed]","[However]","[Sweat]","[Loneliness]","[Sleepy]","[Faint]","[Distressed]","[Grievance]","[Sob]","[Cry]","[Wail]","[Obey]","[Sorry]","[Bye]","[Frown]","[So tired]","[Fall ill]","[Vomit]","[Fall on evil days]","[Surprised]","[Stunned]","[Shut up]","[Due to flat]","[Despise you]","[Rage]","[Angry]","[Mammon]","[Learn from lei feng]","[Wishing you prosperity]","[Waiter]","[Boss]","[Evil]","[Challenge]","[CS]","[Invisible man]","[Bomb]","[Scream]","[Beautiful girl]","[Handsome boy]","[Fortune cat]","[Deal]","[Handclap]","[Handshake]","[Lips]","[Rose]","[Wither]","[Heart]","[Heartbreak]","[Money]","[Shopping]","[Gift]","[Email]","[Phone]","[Cheers]","[Clock]","[Waiting]","[Late]","[Plane]","[Alipay]");//需要被替换的内容
  580. $h= array($list['name'],$firstName[0],$list['orderinfo'],$list['waybill'],$expresscode,$express['url'],$list['name'],$list['bname'],$list['sname'],$list['phone'],$list['zipcode'],$list['country'],$list['province'],$list['city'],$list['address'],$list['product'],$list['saddress'],$list['baddress'],$list['quantity'],$list['parameter'],$product,"/:000","/:001","/:002","/:003","/:004","/:005","/:006","/:007","/:008","/:009","/:010","/:011","/:012","/:013","/:014","/:015","/:016","/:017","/:018","/:019","/:020","/:021","/:022","/:023","/:024","/:025","/:026","/:027","/:028","/:029","/:030","/:031","/:032","/:033","/:034","/:035","/:036","/:037","/:038","/:039","/:040","/:041","/:042","/:043","/:044","/:045","/:046","/:047","/:048","/:049","/:050","/:051","/:052","/:053","/:054","/:055","/:056","/:057","/:058","/:059","/:060","/:061","/:062","/:063","/:064","/:065","/:066","/:067","/:068","/:069","/:070","/:071","/:072","/:073","/:074","/:075","/:076","/:077","/:078","/:079","/:080","/:081","/:082","/:083","/:084","/:085","/:086","/:087","/:088","/:089","/:090","/:091","/:092","/:093","/:094","/:095","/:096","/:097","/:098");//替换的内容
  581. $content = str_replace($t,$h,$content);
  582. if($list['userid'] != '')//用户ID不为空
  583. {
  584. $ch = curl_init();
  585. $url = 'http://39.100.97.180/smt.php';
  586. curl_setopt($ch,CURLOPT_URL,$url);
  587. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  588. curl_setopt($ch,CURLOPT_HEADER,0);
  589. curl_setopt($ch,CURLOPT_POST, 1);
  590. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,600);
  591. //设置post数据
  592. $post = array();
  593. $post['shopid'] = $shop['brandname'];//速卖通店铺ID
  594. $post['userid'] = $list['userid'];//速卖通买家ID
  595. $post['message_type'] = 'order';//消息类型,product(商品)、member(会员,包含店铺)、order(订单)
  596. $post['content'] = $content;//发送内容
  597. $post['code'] = $shop['code'];
  598. $post['order'] = $list['orderinfo'];
  599. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  600. $res = curl_exec($ch);
  601. curl_close($ch);
  602. $res = json_decode($res,true);
  603. if(isset($res['is_success']))
  604. {
  605. return 1;//成功
  606. }
  607. else
  608. {
  609. return isset($res['error_msg'])?$res['error_msg']:(isset($res['sub_msg'])?$res['sub_msg']:'发送失败');
  610. }
  611. }
  612. else
  613. {
  614. return 2;
  615. }
  616. }
  617. } //end class