Sdzxlist.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class Sdzxlist extends Start_Controller {
  3. public function __construct(){
  4. parent::__construct();
  5. $this->load->library('session');
  6. $this->load->model('Model_shop','shop');
  7. $this->load->_model('Model_sdzxlist','sdzxlist');
  8. $this->load->_model('Model_apitt','apitt');
  9. }
  10. //定义方法的调用规则 获取URI第二段值
  11. public function _remap($arg,$arg_array)
  12. {
  13. if($arg == 'index'){
  14. $this->_index();
  15. }elseif($arg == 'edit'){
  16. $this->_edit($arg_array);
  17. }elseif($arg == 'delsc'){
  18. $this->_delsc();
  19. }elseif($arg == 'zczxttznx'){
  20. $this->_zczxttznx();
  21. }else{
  22. exit('No direct script access allowed');
  23. }
  24. }
  25. private function _index(){
  26. if($this->input->method() == 'post'){
  27. $page = $this->input->post('page',true);
  28. $perpage = $this->input->post('perpage',true);
  29. $shop = $this->input->post('shop_id',true);
  30. $ktime = $this->input->post('ktime',true);
  31. $jtime = $this->input->post('jtime',true);
  32. $ktime = strtotime($ktime);
  33. $jtime = strtotime($jtime);
  34. $where = "create_time >= ".$ktime." and create_time < ".$jtime." ";
  35. if(!empty($shop)){
  36. $where .= " and shop_id = ".$shop." ";
  37. }else{
  38. //$where .= " and shop_id in (".$shop_ids.") ";
  39. }
  40. //数据排序
  41. $order_str = "id desc";
  42. if(empty($page))
  43. {
  44. $start = 0;
  45. $perpage = 1;
  46. }
  47. else
  48. {
  49. $start = ($page - 1)*$perpage;
  50. }
  51. $list = $this->sdzxlist->find_all($where,"id,shop,number,type,status,err_desc,create_time,update_time",$order_str,$start,$perpage);
  52. if(empty($list)){
  53. $rows = array('total'=>0,'over'=>1,'pagenum'=>0,'rows'=>([]));
  54. echo json_encode($rows);exit;
  55. }
  56. $type_list = $this->sdzxlist->getType();
  57. $status_list = $this->sdzxlist->getStatus();
  58. $shop_list = $this->shop->find_all("type = 1514");
  59. $shop_id_list = array_column($shop_list,'shopname','id');
  60. foreach($list as $k=>$v){
  61. $list[$k]['type'] = isset($type_list[$v['type']]) ? $type_list[$v['type']] : '无';
  62. $list[$k]['status'] = isset($status_list[$v['status']]) ? $status_list[$v['status']] : '无';
  63. $list[$k]['shop'] = isset($shop_id_list[$v['shop']]) ? $shop_id_list[$v['shop']] : ' ';
  64. $list[$k]['create_time'] = empty($v['create_time']) ? "" : date("Y-m-d H:i",$v['create_time']);
  65. if(empty($v['err_desc']) || $v['err_desc'] == "null"){
  66. $list[$k]['err_desc'] = "请求失败为获取数据!!!";
  67. }
  68. $operate_str = "";
  69. if(empty($v['status'])){
  70. $operate_str .= "<a href='javascript:void(0)' style='margin-right:4px;color: #fff;background-color: #1E90FF;padding:4px 10px;border-radius:5px;font-size:15px' data-id='".$v['id']."' onclick='do_again(this)'>重发</a>";
  71. }
  72. $operate_str .= "<a href='javascript:void(0)' style='margin-right:4px;color: #fff;background-color: #DC143C;padding:4px 10px;border-radius:5px;font-size:15px' data-id='".$v['id']."' onclick='del(this)'>删除</a>";
  73. $list[$k]['update_time'] = $operate_str;
  74. }
  75. $total = $this->sdzxlist->find_count($where);
  76. $pagenum = ceil($total/$perpage);
  77. $over = $total-($start+$perpage);
  78. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($list));
  79. echo json_encode($rows);exit;
  80. }else{
  81. $user = $this->user->get_api($_SESSION['api']);
  82. $usersp = explode('|',trim($user['shop'],'|'));
  83. $shop_tt_list = $this->shop->find_all("type = 1514");
  84. $shop_tt_ids = array_column($shop_tt_list,'id');
  85. $shop_allow_ids = array_intersect($usersp, $shop_tt_ids);
  86. $this->data['usersp'] = implode(",",$shop_allow_ids);
  87. $this->_Template('sdzxlist_index',$this->data);
  88. }
  89. }
  90. private function _edit($arg_array){
  91. if($this->input->method() == 'post'){
  92. exit("no post");
  93. }else{
  94. $id = $arg_array[0];
  95. $info = $this->sdzxlist->read($id);
  96. $shop = $this->shop->read($info['shop']);
  97. $info['shopname'] = $shop['shopname'];
  98. $info['cont'] = json_decode($info['cont'],true);
  99. $this->data['info'] = $info;
  100. $this->_Template('sdzxlist_edit',$this->data);
  101. }
  102. }
  103. private function _delsc(){
  104. if($this->input->method() == 'post'){
  105. $id = $this->input->post('id');
  106. $info = $this->sdzxlist->read($id);
  107. if(empty($info)){
  108. echo json_encode([
  109. 'code'=>-1,
  110. 'msg'=>'数据不存在'
  111. ],JSON_UNESCAPED_UNICODE);
  112. exit;
  113. }
  114. $id = (int)$id;
  115. $this->sdzxlist->remove($id);
  116. echo json_encode([
  117. 'code'=>1,
  118. 'msg'=>'执行成功'
  119. ],JSON_UNESCAPED_UNICODE);
  120. exit;
  121. }else{
  122. echo json_encode([
  123. 'code'=>1,
  124. 'msg'=>'执行成功'
  125. ],JSON_UNESCAPED_UNICODE);
  126. exit;
  127. }
  128. }
  129. private function _zczxttznx(){
  130. if($this->input->method() == 'post'){
  131. $id = $this->input->post('id');
  132. $info = $this->sdzxlist->read($id);
  133. $params = json_decode($info['cont'],true);
  134. $shop = $this->shop->read($info['shop']);
  135. $list = [];
  136. $list['user_id'] = $params['post']['buyer_user_id'];
  137. $res = $this->apitt->openZnxWindow($list,$shop);
  138. if(empty($res)){
  139. echo json_encode([
  140. 'code'=>-1,
  141. 'msg'=>'获取会话ID失败'
  142. ]);exit;
  143. }
  144. if(!isset($res['data']['conversation_id'])){
  145. echo json_encode([
  146. 'code'=>-1,
  147. 'msg'=>$res['message']
  148. ]);exit;
  149. }
  150. $conversation_id = $res['data']['conversation_id'];
  151. $notice = $params['content'];
  152. $rr = $this->apitt->sendZnxMessage($shop,$notice,$conversation_id);
  153. if(empty($rr)){
  154. echo json_encode([
  155. 'code'=>-1,
  156. 'msg'=>'发送消息失败'
  157. ]);exit;
  158. }
  159. if(isset($rr['data']['message_id']))
  160. {
  161. echo json_encode([
  162. 'code'=>1,
  163. 'msg'=>'发送成功'
  164. ]);exit;
  165. }
  166. else
  167. {
  168. echo json_encode([
  169. 'code'=>-1,
  170. 'msg'=>$rr['message']
  171. ]);exit;
  172. }
  173. }else{
  174. echo json_encode([
  175. 'code'=>-1,
  176. 'msg'=>'执行失败'
  177. ]);exit;
  178. }
  179. }
  180. }