Apipf.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3. /**
  4. * 本类是为了处理 erp协同其他系统,通过其他系统传递的条件 返回所需信息
  5. */
  6. class Apipf extends Start_Controller{
  7. public function __construct(){
  8. parent::__construct();
  9. $this->load->_model('Model_logic_order','logic_order');
  10. $this->load->_model('Model_logic_tools','logic_tools');
  11. $this->load->_model("Model_logic_ding",'logic_ding');
  12. $this->load->_model('Model_customer','customer');
  13. $this->load->_model('Model_typeclass','typeclass');
  14. }
  15. private $key = "bpng!pjgirv6amnfr"; //加密所需要到的key
  16. private $iv = "k4k!94m66oojtm2w";//加密所需要到的iv
  17. private $api = "202503121009@ly";
  18. //定义方法的调用规则 获取URI第二段值
  19. public function _remap($arg,$arg_array)
  20. {
  21. if($arg == 'checkMoreThree')//添加
  22. {
  23. $this->_checkMoreThree();
  24. }
  25. elseif($arg == 'customerData')
  26. {
  27. $this->_customerData();
  28. }
  29. elseif($arg == 'orderTbAllData')
  30. {
  31. $this->_orderTbAllData();
  32. }
  33. elseif($arg == 'orderTbData')
  34. {
  35. $this->_orderTbData();
  36. }
  37. else
  38. {
  39. exit('No direct script access allowed');
  40. }
  41. }
  42. //检测客户是否超过3次且为传输
  43. public function _checkMoreThree(){
  44. $api = $this->input->get('api',true);
  45. if($api != $this->api){
  46. die("No data to be executed");
  47. }
  48. $hour = date("H");
  49. $minute = date("i");
  50. if($hour != 20){
  51. die("Execution conditions hour do not allow");
  52. }
  53. if(($minute >= 10)&&($minute <=20)){
  54. $this->db->query("update crowd_customer set more_three = 1 where num >= 3 and more_three = 0");
  55. die("No executable data available");
  56. }else{
  57. die("Execution conditions minute do not allow !");
  58. }
  59. }
  60. /***
  61. * 上传没有给批发站没有传递的客户信息
  62. */
  63. public function _customerData(){
  64. $list = $this->customer->find_all("more_three = 1","id,shop,source,name,email,phone,money,num,country,province,city,street,address,address2,zipcode",'id asc',0,100);
  65. $list_ids = [];
  66. $send_list = [];
  67. foreach($list as $k=>$v){
  68. $list_ids[] = $v['id'];
  69. $send_list[] = [
  70. 'name'=>$v['name'],
  71. 'email'=>$v['email'],
  72. 'telephone'=>$v['phone'],
  73. 'money'=>$v['money'],
  74. 'num'=>$v['num'],
  75. 'country'=>$v['country'],
  76. 'province'=>$v['province'],
  77. 'city'=>$v['city'],
  78. 'street'=>$v['street'],
  79. 'address'=>$v['address'].$v['address2'],
  80. 'zipcode'=>$v['zipcode']
  81. ];
  82. }
  83. $header = [];
  84. $url = "";
  85. if(empty($send_list)){
  86. die("There is no customer data to be synchronized");
  87. }
  88. die("update crowd_customer set more_three = 2 where id in (".implode(",",$list_ids).")");
  89. $this->db->query("update crowd_customer set more_three = 2 where id in (".implode(",",$list_ids).")");
  90. // $res = $this->sendHttp($url,$header,$send_list);
  91. // if($res){
  92. // $this->db->query("update crowd_customer set more_three = 2 where id in (".implode(",",$list_ids).")");
  93. // }
  94. }
  95. public function _orderTbAllData(){
  96. $typeclass = $this->typeclass->find_all("classid = 29","id,classtitle,title,spare");
  97. $typeclass = array_column($typeclass,null,'id');
  98. $list = $this->customer->find_all("more_three = 2","id,shop,name,email",'id asc',0,100);
  99. foreach($list as $k=>$v){
  100. $order_list = $this->getOrder($v,$typeclass);
  101. if(empty($order_list)){
  102. continue;
  103. }
  104. }
  105. }
  106. private function getOrder($v,$typeclass){
  107. $fdata = $this->fullorder->find_all('email = "'.$customer['email'].'" and shop = "'.$customer['shop'].'" and mergeid = 0 and reviewtime <= ','shop,orderinfo,issku,quantity,fpdata,state,product,name,email,dtime,shouldmoney,shipremarks','id desc');
  108. $ret_list = [];
  109. foreach ($fdata as $k=>$v)
  110. {
  111. $sku_list = [];
  112. $issku_arr = explode(",",trim($v['issku'],','));
  113. $quantity_arr = explode(";",trim($v['quantity'],";"));
  114. $product_arr = explode(",",trim($v['product'],";"));
  115. foreach($issku_arr as $key => $item){
  116. $sku_list[] = [
  117. 'sku'=>$item,
  118. 'qty'=>isset($quantity_arr[$key])?$quantity_arr[$key]:1,
  119. 'product_name'=>isset($product_arr[$key])?$product_arr[$key]:"",
  120. ];
  121. }
  122. $goods_list = [];
  123. $fpdata_arr = explode(";",trim($v['fpdata'],";"));
  124. if(!empty($tmp_data[1])){
  125. foreach($fpdata_arr as $key => $item){
  126. $tmp_data = explode("|",$item);
  127. $goods_list[] = [
  128. 'goods_name'=>$tmp_data[1],
  129. 'qty'=>$tmp_data[2]
  130. ];
  131. }
  132. }else{
  133. continue;
  134. }
  135. $ret_list[] = [
  136. 'shop'=>$v['shop'],
  137. 'orderinfo'=>$v['orderinfo'],
  138. 'sku_list'=>$sku_list,
  139. 'goods_list'=>$goods_list,
  140. 'state'=>isset($typeclass[$v['state']])?$typeclass[$v['state']]['spare']:"",
  141. 'dtime'=>date('Y-m-d',$v['dtime']),
  142. 'name'=>$v['name'],
  143. 'email'=>$v['email'],
  144. 'shouldmoney'=>$v['shouldmoney'],
  145. 'shipremarks'=>$v['shipremarks']
  146. ];
  147. }
  148. return $fdata;
  149. }
  150. public function _orderTbData(){
  151. $fdata = $this->fullorder->find_all('id = 1228433','shop,orderinfo,issku,quantity,fpdata,state,product,name,email,dtime,shouldmoney,shipremarks','id desc');
  152. $ret_list = [];
  153. echo "<pre>";
  154. foreach ($fdata as $k=>$v)
  155. {
  156. var_dump($v);
  157. $sku_list = [];
  158. $issku_arr = explode(",",trim($v['issku'],','));
  159. $quantity_arr = explode(";",trim($v['quantity'],";"));
  160. $product_arr = explode(",",trim($v['product'],";"));
  161. foreach($issku_arr as $key => $item){
  162. $sku_list[] = [
  163. 'sku'=>$item,
  164. 'qty'=>isset($quantity_arr[$key])?$quantity_arr[$key]:1,
  165. 'product_name'=>isset($product_arr[$key])?$product_arr[$key]:"",
  166. ];
  167. }
  168. $goods_list = [];
  169. $fpdata_arr = explode(";",trim($v['fpdata'],";"));
  170. if(!empty($tmp_data[1])){
  171. foreach($fpdata_arr as $key => $item){
  172. $tmp_data = explode("|",$item);
  173. $goods_list[] = [
  174. 'goods_name'=>$tmp_data[1],
  175. 'qty'=>$tmp_data[2]
  176. ];
  177. }
  178. }else{
  179. continue;
  180. }
  181. $ret_list[] = [
  182. 'shop'=>$v['shop'],
  183. 'orderinfo'=>$v['orderinfo'],
  184. 'sku_list'=>$sku_list,
  185. 'goods_list'=>$goods_list,
  186. 'state'=>isset($typeclass[$v['state']])?$typeclass[$v['state']]['spare']:"",
  187. 'dtime'=>date('Y-m-d',$v['dtime']),
  188. 'name'=>$v['name'],
  189. 'email'=>$v['email'],
  190. 'shouldmoney'=>$v['shouldmoney'],
  191. 'shipremarks'=>$v['shipremarks']
  192. ];
  193. }
  194. echo "<pre>";
  195. var_dump($ret_list);
  196. }
  197. private function sendHttp($url,$header,$list){
  198. $ch = curl_init();
  199. curl_setopt($ch, CURLOPT_URL, $url);
  200. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  201. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  202. curl_setopt($ch, CURLINFO_HEADER_OUT, TRUE);
  203. curl_setopt($ch, CURLOPT_POST, 1);
  204. curl_setopt($ch, CURLOPT_POSTFIELDS, $list);
  205. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  206. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  207. $res = curl_exec($ch);
  208. $res = json_decode($res,true);
  209. return $res;
  210. }
  211. }