Kdniao.php 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class Kdniao extends Start_Controller {
  3. public function __construct(){
  4. parent::__construct();
  5. $this->load->library('session');
  6. $this->load->_model('Model_fullorder','fullorder');
  7. $this->load->_model('Model_fullordertt','fullordertt');
  8. $this->load->_model('Model_notice','notice');
  9. $this->load->_model('Model_kdniao','kdniao');
  10. $this->load->_model('Model_shop','shop');
  11. $this->load->_model('Model_express','express');
  12. $this->load->_model('Model_warehouse','warehouse');
  13. }
  14. //定义方法的调用规则 获取URI第二段值
  15. public function _remap($arg,$arg_array)
  16. {
  17. if($arg == 'js')//添加
  18. {
  19. $this->_js();
  20. }
  21. }
  22. public function _js()
  23. {
  24. $post = $this->input->post(NULL, TRUE);
  25. $data = $this->input->post('RequestData',true);
  26. if(isset($data))
  27. {
  28. $data = json_decode($data,true);//josn转数组
  29. foreach ($data['Data'] as $value)//循环出每个运单信息
  30. {
  31. $rows = "";
  32. $waybill = $value['LogisticCode'];//运单号
  33. $fullorder = $this->fullorder->get_waybill($waybill);//查找此运单号
  34. if($fullorder)//如果有此运单号
  35. {
  36. if($fullorder['exstate'] != $value['State'])//如果状态已更新
  37. {
  38. $notice = $this->notice->get_type($fullorder['shop'],2,$value['State'],0);//查找消息配置
  39. if($notice)//如果有此消息配置
  40. {
  41. $warehouse = $this->warehouse->read($fullorder['type']);
  42. if($notice['type'] == 2)//发送邮件
  43. {
  44. $st = $this->_email($notice['content'],$fullorder,$warehouse['company']);//发送数据
  45. }
  46. else
  47. {
  48. $st = 2;
  49. //订单留言 AE需要 1.成功2.失败
  50. }
  51. }
  52. foreach ($value['Traces'] as $v)//物流详情
  53. {
  54. $rows .= "<p>时间:".$v['AcceptTime']." 状态:".$v['AcceptStation']."</p>";
  55. }
  56. $this->fullorder->save(array('exstate'=>$value['State'],'fsstate'=>$st,'content'=>$rows),$fullorder['id']);
  57. }
  58. }
  59. }
  60. }
  61. $echo = array("EBusinessID"=>$data['EBusinessID'],"UpdateTime"=>date('Y-m-d H:i:s',time()),"Success"=>true,"Reason"=>"");
  62. echo json_encode($echo);
  63. }
  64. public function _email($content,$data,$shopname)
  65. {
  66. $express = $this->express->read($data['express']);
  67. $t= array('$userName','$orderid','$trackingNumber','$expressCompany','$contactPerson','$mobileNo','$zip','$recipientAddress');//需要被替换的内容
  68. $h= array($data['client'],$data['orderinfo'],$data['waybill'],$express['title'],$data['name'],$data['phone'],$data['zipcode'],$data['address']);//替换的内容
  69. $content = str_replace($t,$h,$content);
  70. $this->load->library('email');
  71. $config['protocol'] = 'smtp';
  72. $config['smtp_host'] = 'smtpdm-ap-southeast-1.aliyun.com';
  73. $config['smtp_port'] = 465;
  74. $config['smtp_user'] = 'service@email.supernovahair.com';
  75. $config['smtp_pass'] = 'LONGyihair374';
  76. $config['smtp_crypto'] = 'ssl';
  77. $config['crlf'] = "\r\n";
  78. $config['newline'] = "\r\n";
  79. $this->email->initialize($config);
  80. $this->email->from('service@email.supernovahair.com',$shopname);
  81. $this->email->to($data['email']);//收件
  82. $this->email->subject('The product you purchased has a new progress');//标题
  83. $this->email->message($content);//内容
  84. if ( ! $this->email->send())
  85. {
  86. return 2;
  87. }
  88. else
  89. {
  90. return 1;
  91. }
  92. }
  93. }