Model_notice.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  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. }
  11. public function get_type($shop,$type,$logisticstatus,$ordertatus)//查找符合消息发送条件的信息
  12. {
  13. if($type == 1)
  14. {
  15. return $this->find("shop = '$shop' and type = '$type' and ordertatus = '$ordertatus' and state = 1 and ktime < 'time()' and jtime < 'time()'");
  16. }
  17. else if($type == 2)
  18. {
  19. return $this->find("shop = '$shop' and type = '$type' and logisticstatus = '$logisticstatus' and state = 1 and ktime < 'time()' and jtime < 'time()'");
  20. }
  21. else if($type == 3)
  22. {
  23. return $this->find("shop = '$shop' and type = '$type' and state = 1 and ktime < 'time()' and jtime < 'time()'");
  24. }
  25. }
  26. //所属店铺、模板类型、物流状态/订单状态
  27. /** 通过订单状态 */
  28. public function get_ordertatus($ordertatus)
  29. {
  30. return $this->find("ordertatus = '$ordertatus'");
  31. }
  32. public function get_go($list,$shop,$genre,$option)
  33. {
  34. //aptsmt获取订单:崔付款、确认地址
  35. $time = time();
  36. $data = $this->find("shop = '".$shop['id']."' and ".$genre." = '$option' and ktime < '$time' and jtime > '$time' and state = 1");//$genre三种模式:订单状态、物流跟踪、营销。启用状态下,有效期内搜索该店铺设置
  37. if($data)//如果可用模板配置
  38. {
  39. $message=2;
  40. $list['orderinfo'] = ($message==1)?substr($list['orderinfo'],1):$list['orderinfo'];
  41. if($message==1)
  42. {
  43. $expresscode = (isset($express['title']))?$express['title']:'';
  44. }
  45. else
  46. {
  47. $expresscode = (isset($express['aecode']))?$express['aecode']:'';
  48. }
  49. if(!isset($list['country']))
  50. {
  51. $list['waybill'] = '';
  52. $list['phone'] = '';
  53. $list['zipcode'] = '';
  54. $list['country'] = '';
  55. $list['province'] = '';
  56. $list['city'] = '';
  57. $list['address'] = '';
  58. $list['product'] = '';
  59. }
  60. $express['url'] = (isset($express['url']))?$express['url']:'';
  61. $list['userName'] = (isset($list['userName']))?$list['userName']:'';
  62. $list['orderid'] = (isset($list['orderid']))?$list['orderid']:'';
  63. $list['name'] = (isset($list['name']))?$list['name']:'';
  64. $list['bname'] = (isset($list['bname']))?$list['bname']:'';
  65. $list['sname'] = (isset($list['sname']))?$list['sname']:'';
  66. $list['saddress'] = (isset($list['saddress']))?$list['saddress']:'';
  67. $list['baddress'] = (isset($list['baddress']))?$list['baddress']:'';
  68. $list['quantity'] = (isset($list['quantity']))?(($list['quantity'] > '1')?$list['quantity'].' packages of':''):'';
  69. $list['parameter'] = (isset($list['parameter']))?$list['parameter']:'';
  70. $ProductSKU = (isset($list['issku']))?$list['issku']:$list['sku'];
  71. $yjtime = (isset($express['yjtime']))?$express['yjtime']:'';
  72. $product = '';
  73. if($list['product'] != '')
  74. {
  75. $list['product'] = str_replace("'","",$list['product']);
  76. if($list['link'] != '' && $list['source'] != '1')
  77. {
  78. $pt = explode(',',$list['product']);
  79. $lk = explode(',',$list['link']);
  80. for($i=0;$i<count($pt);$i++)
  81. {
  82. $a = $pt[$i];
  83. //$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];
  84. if(isset($lk[$i]) && isset($content) && stripos($content,'<img') !== false)
  85. {
  86. $product .= ($product != '')?' , <a href="'.$lk[$i].'" target="_blank">'.$a.'</a>':'<a href="'.$lk[$i].'" target="_blank">'.$a.'</a>';
  87. }
  88. else
  89. {
  90. $product .= ($product != '')?' , '.$a:$a;
  91. }
  92. }
  93. }
  94. }
  95. $ProductName = '';
  96. $st = explode(';',trim($list['fpdata'],';'));
  97. foreach ($st as $v)
  98. {
  99. $v = explode('|',trim($v,'|'));
  100. $th = $this->producttitle->get_title($v[1]);
  101. if($th)
  102. {
  103. $ProductName .= $th['th'].', ';
  104. }
  105. else
  106. {
  107. $ProductName .= $v[1].', ';
  108. }
  109. }
  110. $ProductName = trim($ProductName,', ');
  111. $firstName = explode(' ',$list['name']);
  112. $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]");//需要被替换的内容
  113. $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");//替换的内容
  114. $content = str_replace($t,$h,$data['content']);
  115. if($data['message'] == 1)//如果是发送邮件
  116. {
  117. if(!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$list['email']))
  118. {
  119. return '邮箱地址错误,请检查';exit;
  120. }
  121. $emailbt = ($data['emailtitle'] != '')?str_replace($t,$h,$data['emailtitle']):'The product you purchased has a new progress';
  122. $this->load->library('email');
  123. $config['protocol'] = 'smtp';
  124. $config['smtp_host'] = 'smtpdm-ap-southeast-1.aliyun.com';
  125. $config['smtp_port'] = 465;
  126. $config['smtp_user'] = 'service@email.supernovahair.com';
  127. $config['smtp_pass'] = 'LONGyihair374';
  128. $config['smtp_crypto'] = 'ssl';
  129. $config['crlf'] = "\r\n";
  130. $config['newline'] = "\r\n";
  131. $this->email->initialize($config);
  132. $this->email->set_newline("\r\n");
  133. $this->email->from('service@email.supernovahair.com',$shopname);
  134. $this->email->to($list['email']);//收件
  135. $this->email->subject($emailbt);//标题
  136. $this->email->message($content);//内容
  137. if ($this->email->send())
  138. {
  139. return 1;//成功
  140. }
  141. else
  142. {
  143. return '发送失败';
  144. }
  145. }
  146. else if($data['message'] == 2 && $list['userid'] != '')//如果是速卖通站内信,用户ID不为空
  147. {
  148. $ch = curl_init();
  149. $url = 'http://39.100.97.180/smtold.php';
  150. curl_setopt($ch,CURLOPT_URL,$url);
  151. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  152. curl_setopt($ch,CURLOPT_HEADER,0);
  153. curl_setopt($ch,CURLOPT_POST, 1);
  154. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,600);
  155. //设置post数据
  156. $post = array();
  157. $post['shopid'] = $shop['brandname'];//速卖通店铺ID
  158. $post['userid'] = $list['userid'];//速卖通买家ID
  159. $post['message_type'] = 'order';//消息类型,product(商品)、member(会员,包含店铺)、order(订单)
  160. $post['content'] = $content;//发送内容
  161. $post['code'] = $shop['code'];
  162. $post['order'] = $list['orderinfo'];
  163. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  164. $res = curl_exec($ch);
  165. curl_close($ch);
  166. $res = json_decode($res,true);
  167. if(isset($res['is_success']))
  168. {
  169. return 1;//成功
  170. }
  171. else
  172. {
  173. return isset($res['error_msg'])?$res['error_msg']:(isset($res['sub_msg'])?$res['sub_msg']:'发送失败');
  174. }
  175. }
  176. else
  177. {
  178. return '邮箱错误或者没有UserID';
  179. }
  180. }
  181. else
  182. {
  183. return '无可用站内信模板';
  184. }
  185. }
  186. public function get_god($list,$shop,$express,$notice)//单个订单整体模式
  187. {
  188. if( isset($shop['id']) && ($shop['id'] == 5)){
  189. //暂时不写井号 避免出问题
  190. $list['orderinfo'] = substr($list['orderinfo'],1);
  191. }else{
  192. $list['orderinfo'] = ($notice['message']==1)?substr($list['orderinfo'],1):$list['orderinfo'];
  193. }
  194. if($notice['message']==1)
  195. {
  196. $expresscode = (isset($express['title']))?$express['title']:'';
  197. }
  198. else
  199. {
  200. $expresscode = (isset($express['aecode']))?$express['aecode']:'';
  201. }
  202. if(!isset($list['country']))
  203. {
  204. $list['waybill'] = '';
  205. $list['phone'] = '';
  206. $list['zipcode'] = '';
  207. $list['country'] = '';
  208. $list['province'] = '';
  209. $list['city'] = '';
  210. $list['address'] = '';
  211. $list['product'] = '';
  212. }
  213. $express['url'] = (isset($express['url']))?$express['url']:'';
  214. $list['userName'] = (isset($list['userName']))?$list['userName']:'';
  215. $list['orderid'] = (isset($list['orderid']))?$list['orderid']:'';
  216. $list['name'] = (isset($list['name']))?$list['name']:'';
  217. $list['bname'] = (isset($list['bname']))?$list['bname']:'';
  218. $list['sname'] = (isset($list['sname']))?$list['sname']:'';
  219. $list['saddress'] = (isset($list['saddress']))?$list['saddress']:'';
  220. $list['baddress'] = (isset($list['baddress']))?$list['baddress']:'';
  221. $list['quantity'] = (isset($list['quantity']))?(($list['quantity'] > '1')?$list['quantity'].' packages of':''):'';
  222. $list['parameter'] = (isset($list['parameter']))?$list['parameter']:'';
  223. $list['waybill'] = (isset($list['waybill']))?$list['waybill']:'';
  224. //$ProductSKU = (isset($list['issku']))?$list['issku']:$list['sku'];
  225. $ProductSKU = "";
  226. if(isset($list['issku'])){
  227. $ProductSKU = $list['issku'];
  228. }else{
  229. if(isset($list['sku'])){
  230. $ProductSKU = $list['sku'];
  231. }
  232. }
  233. $yjtime = (isset($express['yjtime']))?$express['yjtime']:'';
  234. $product = '';
  235. if($list['product'] != '')
  236. {
  237. $list['product'] = str_replace("'","",$list['product']);
  238. if($list['link'] != '' && $list['source'] != '1')
  239. {
  240. $pt = explode(',',$list['product']);
  241. $lk = explode(',',$list['link']);
  242. for($i=0;$i<count($pt);$i++)
  243. {
  244. $a = $pt[$i];
  245. //$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];
  246. if(isset($lk[$i]) && stripos($notice['content'],'<img') !== false)
  247. {
  248. $product .= ($product != '')?' , <a href="'.$lk[$i].'" target="_blank">'.$a.'</a>':'<a href="'.$lk[$i].'" target="_blank">'.$a.'</a>';
  249. }
  250. else
  251. {
  252. $product .= ($product != '')?' , '.$a:$a;
  253. }
  254. }
  255. }else{
  256. if(isset($shop['id']) && ($shop['id'] == 5) && $list['source'] != '1'){
  257. $pt = explode(',',$list['product']);
  258. $lk = explode(',',$list['link']);
  259. for($i=0;$i<count($pt);$i++)
  260. {
  261. $a = $pt[$i];
  262. //$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];
  263. if(isset($lk[$i]) && stripos($notice['content'],'<img') !== false)
  264. {
  265. $product .= ($product != '')?' , <a href="'.$lk[$i].'" target="_blank">'.$a.'</a>':'<a href="'.$lk[$i].'" target="_blank">'.$a.'</a>';
  266. }
  267. else
  268. {
  269. $product .= ($product != '')?' , '.$a:$a;
  270. }
  271. }
  272. }
  273. }
  274. }
  275. //$this->logic_ding->sendToDing("监听同步平台信息".$list['orderinfo']."的product【".$list['product']."】以及对应的pt:【".json_encode($pt)."】最终生成的product".$product);
  276. if(empty($data['fpdata'])){
  277. // $this->logic_ding->sendToDing("监听同步平台信息缺失fpdata".$list['orderinfo']."的传递的信息【".json_encode($list)."】");
  278. }
  279. $ProductName = '';
  280. if(empty($list['fpdata'])){
  281. $st = [];
  282. }else{
  283. $st = explode(';',trim($list['fpdata'],';'));
  284. }
  285. foreach ($st as $v)
  286. {
  287. $v = explode('|',trim($v,'|'));
  288. if(isset($v[1]))
  289. {
  290. $th = $this->producttitle->get_title($v[1]);
  291. if($th)
  292. {
  293. $ProductName .= $th['th'].', ';
  294. }
  295. else
  296. {
  297. $ProductName .= $v[1].', ';
  298. }
  299. }
  300. }
  301. $ProductName = trim($ProductName,', ');
  302. $firstName = explode(' ',$list['name']);
  303. $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]");//需要被替换的内容
  304. $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");//替换的内容
  305. $notice['content'] = str_replace($t,$h,$notice['content']);
  306. //$this->logic_ding->sendToDing("监听同步平台信息".$list['orderinfo']."【".$notice['content']."】");
  307. if($notice['emailtitle'] != '')
  308. {
  309. $notice['emailtitle'] = str_replace($t,$h,$notice['emailtitle']);
  310. $emailbt = $notice['emailtitle'];
  311. }
  312. else
  313. {
  314. $emailbt = $shop['brandname'].' Hair Service- Order Confirmation #'.$list['orderinfo'];
  315. }
  316. if($notice['message'] == 1)//如果是发送邮件
  317. {
  318. if(!$notice['email']['smtp_host'] || !$notice['email']['smtp_user'] || !$notice['email']['smtp_pass'])
  319. {
  320. return '此店铺没有配置邮件服务器信息!';exit;
  321. }
  322. if(!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$list['email']))
  323. {
  324. return '邮箱地址错误,请检查';exit;
  325. }
  326. if($notice['email']['smtp_host'] == 'smtp.gmail.com')
  327. {
  328. $ch = curl_init();
  329. $url = 'http://e.wepolicy.cn/';
  330. curl_setopt($ch,CURLOPT_URL,$url);
  331. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  332. curl_setopt($ch,CURLOPT_HEADER,0);
  333. curl_setopt($ch,CURLOPT_POST, 1);
  334. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,600);
  335. //设置post数据
  336. $post = array();
  337. $post['notice'] = $notice;
  338. $post['list'] = $list;
  339. $post['shop'] = $order;
  340. $post['emailbt'] = $emailbt;
  341. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  342. $res = curl_exec($ch);
  343. curl_close($ch);
  344. $res = json_decode($res,true);
  345. if($res)
  346. {
  347. return $res;//成功
  348. }
  349. else
  350. {
  351. return '发送失败';
  352. }
  353. }
  354. else
  355. {
  356. $this->load->library('email');
  357. $config['protocol'] = $notice['email']['protocol'];
  358. $config['smtp_host'] = $notice['email']['smtp_host'];
  359. $config['smtp_port'] = $notice['email']['smtp_port'];
  360. $config['smtp_timeout']='30';
  361. $config['smtp_user'] = $notice['email']['smtp_user'];
  362. $config['smtp_pass'] = $notice['email']['smtp_pass'];
  363. $config['smtp_crypto'] = $notice['email']['smtp_crypto'];
  364. $config['crlf'] = "\r\n";
  365. $config['newline'] = "\r\n";
  366. if(stripos($notice['content'],'</p>') !== false)
  367. {
  368. $notice['content'] = str_replace(array('<p>','<p style="'),array('<p style="margin:0px;">','<p style="margin:0px;'),$notice['content']);
  369. $config['mailtype'] = "html";
  370. }
  371. $this->email->initialize($config);
  372. $this->email->set_newline("\r\n");
  373. $this->email->from($notice['email']['smtp_user'],$shop['shopname']);//发送方
  374. $this->email->to($list['email']);//收件
  375. $this->email->subject($emailbt);//标题
  376. $this->email->message($notice['content']);//内容
  377. if ($this->email->send())
  378. {
  379. return 1;
  380. }
  381. else
  382. {
  383. return $this->email->print_debugger(array('headers'));
  384. }
  385. }
  386. }
  387. else if($notice['message'] == 2 && $list['userid'] != '')//如果是速卖通站内信,用户ID不为空
  388. {
  389. /**
  390. $ch = curl_init();
  391. $url = 'http://39.100.97.180/smtold.php';
  392. curl_setopt($ch,CURLOPT_URL,$url);
  393. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  394. curl_setopt($ch,CURLOPT_HEADER,0);
  395. curl_setopt($ch,CURLOPT_POST, 1);
  396. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,600);
  397. //设置post数据
  398. $post = array();
  399. $post['shopid'] = $shop['brandname'];//速卖通店铺ID
  400. $post['userid'] = $list['userid'];//速卖通买家ID
  401. $post['message_type'] = 'order';//消息类型,product(商品)、member(会员,包含店铺)、order(订单)
  402. $post['content'] = $notice['content'];//发送内容
  403. $post['code'] = $shop['code'];
  404. $post['order'] = $list['orderinfo'];
  405. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  406. $res = curl_exec($ch);
  407. curl_close($ch);
  408. $res = json_decode($res,true);
  409. if(isset($res['is_success']))
  410. {
  411. return 1;//成功
  412. }
  413. else
  414. {
  415. return $res;
  416. }
  417. **/
  418. }
  419. else if($notice['message'] == 3 && $list['user_id'] != '')//如果是TT会话,用户ID不为空
  420. {
  421. $url = 'https://open-api.tiktokglobalshop.com';
  422. $link = '/customer_service/202309/conversations';
  423. $time = time();
  424. $post['buyer_user_id'] = $list['user_id'];
  425. $queryParams['shop_cipher'] =$shop['shop_cipher'];
  426. //$queryParams['shop_id'] =$shop['codeid'];
  427. $queryParams['app_key'] =$shop['app_key'];
  428. $queryParams['timestamp'] =$time;
  429. $link .= '?'.http_build_query($queryParams);
  430. $sign = $this->apitt->sign($link,$shop['app_secret'],$post);
  431. $url .= $link.'&sign='.$sign;
  432. $headers = array('Content-Type: application/json','x-tts-access-token:'.$shop['token']);
  433. $res = $this->apitt->su_curl($post,$url,$headers);
  434. $res = json_decode($res,true);
  435. if(isset($res['data']['conversation_id']))
  436. {
  437. $f = $this->_ttfs($shop,$notice['content'],$res['data']['conversation_id']);
  438. if(isset($f['data']['message_id']))
  439. {
  440. return 1;//成功
  441. }
  442. else
  443. {
  444. return isset($f['message'])?'B:'.$f['message']:'发送失败';
  445. }
  446. }
  447. else
  448. {
  449. return isset($res['message'])?'A:'.$res['message']:'发送失败';
  450. }
  451. }
  452. else
  453. {
  454. return '无可用发送平台!';
  455. }
  456. }
  457. public function _ttfs($shop,$notice,$conversation_id)//TT发送信息
  458. {
  459. $url = 'https://open-api.tiktokglobalshop.com';
  460. $link = '/customer_service/202309/conversations/'.$conversation_id.'/messages';
  461. $time = time();
  462. $notice = str_replace('</p>','\n',$notice);
  463. $post['type'] = 'TEXT';
  464. $post['content'] = '{"content": "'.strip_tags($notice).'"}';
  465. //$queryParams['access_token'] = $shop['token'];
  466. $queryParams['shop_cipher'] = $shop['shop_cipher'];
  467. $queryParams['shop_id'] = $shop['codeid'];
  468. $queryParams['app_key'] = $shop['app_key'];
  469. $queryParams['version'] = '202309';
  470. $queryParams['timestamp'] =$time;
  471. $link .= '?'.http_build_query($queryParams);
  472. $sign = $this->apitt->sign($link,$shop['app_secret'],$post);
  473. $url .= $link.'&sign='.$sign;
  474. $headers = array('Content-Type: application/json','x-tts-access-token:'.$shop['token']);
  475. $res = $this->apitt->su_curl($post,$url,$headers);
  476. $res = json_decode($res,true);
  477. return $res;
  478. }
  479. public function get_smtone($list,$shop,$content)//单个订单非快递信息模式模式
  480. {
  481. if(!isset($list['country']))
  482. {
  483. $list['waybill'] = '';
  484. $list['phone'] = '';
  485. $list['zipcode'] = '';
  486. $list['country'] = '';
  487. $list['province'] = '';
  488. $list['city'] = '';
  489. $list['address'] = '';
  490. $list['product'] = '';
  491. }
  492. $expresscode = (isset($express['aecode']))?$express['aecode']:'';
  493. $express['url'] = (isset($express['url']))?$express['url']:'';
  494. $list['userName'] = (isset($list['userName']))?$list['userName']:'';
  495. $list['orderid'] = (isset($list['orderid']))?$list['orderid']:'';
  496. $list['name'] = (isset($list['name']))?$list['name']:'';
  497. $list['bname'] = (isset($list['bname']))?$list['bname']:'';
  498. $list['sname'] = (isset($list['sname']))?$list['sname']:'';
  499. $product = '';
  500. if($list['product'] != '')
  501. {
  502. $list['product'] = str_replace("'","",$list['product']);
  503. if($list['link'] != '' && $list['source'] != '1')
  504. {
  505. $pt = explode(',',$list['product']);
  506. $lk = explode(',',$list['link']);
  507. for($i=0;$i<count($pt);$i++)
  508. {
  509. $a = $pt[$i];
  510. //$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];
  511. if(isset($lk[$i]) && stripos($content,'<img') !== false)
  512. {
  513. $product .= ($product != '')?' , <a href="'.$lk[$i].'" target="_blank">'.$a.'</a>':'<a href="'.$lk[$i].'" target="_blank">'.$a.'</a>';
  514. }
  515. else
  516. {
  517. $product .= ($product != '')?' , '.$a:$a;
  518. }
  519. }
  520. }
  521. }
  522. $firstName = explode(' ',$list['name']);
  523. $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]");//需要被替换的内容
  524. $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");//替换的内容
  525. $content = str_replace($t,$h,$content);
  526. if($list['userid'] != '')//用户ID不为空
  527. {
  528. $ch = curl_init();
  529. $url = 'http://39.100.97.180/smt.php';
  530. curl_setopt($ch,CURLOPT_URL,$url);
  531. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  532. curl_setopt($ch,CURLOPT_HEADER,0);
  533. curl_setopt($ch,CURLOPT_POST, 1);
  534. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,600);
  535. //设置post数据
  536. $post = array();
  537. $post['shopid'] = $shop['brandname'];//速卖通店铺ID
  538. $post['userid'] = $list['userid'];//速卖通买家ID
  539. $post['message_type'] = 'order';//消息类型,product(商品)、member(会员,包含店铺)、order(订单)
  540. $post['content'] = $content;//发送内容
  541. $post['code'] = $shop['code'];
  542. $post['order'] = $list['orderinfo'];
  543. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  544. $res = curl_exec($ch);
  545. curl_close($ch);
  546. $res = json_decode($res,true);
  547. if(isset($res['is_success']))
  548. {
  549. return 1;//成功
  550. }
  551. else
  552. {
  553. return isset($res['error_msg'])?$res['error_msg']:(isset($res['sub_msg'])?$res['sub_msg']:'发送失败');
  554. }
  555. }
  556. else
  557. {
  558. return 2;
  559. }
  560. }
  561. } //end class