Goodimglibrary.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class Goodimglibrary extends Start_Controller {
  3. public function __construct(){
  4. parent::__construct();
  5. $this->load->library('session');
  6. $this->load->_model('Model_goodimgs','goodimgs');
  7. $this->load->_model('Model_goods','goods');
  8. }
  9. private $show_url = "https://lyerposs.wepolicy.cn";
  10. public function _remap($arg,$arg_array)
  11. {
  12. if($arg=="detail"){
  13. //$this->_detial($arg_array);
  14. }elseif($arg=="edit"){
  15. $this->_editData($arg_array);
  16. }else{
  17. $this->_index();
  18. }
  19. }
  20. private function _index(){
  21. if($this->input->method() == 'post'){
  22. $page = $this->input->post('page',true);
  23. $perpage = $this->input->post('perpage',true);
  24. $title = $this->input->post('title',true);
  25. $zh= $this->input->post('zh',true);
  26. $sku = $this->input->post('sku',true);
  27. $category = $this->input->post('category',true);
  28. $category = trim($category);
  29. $grade = $this->input->post('grade',true);
  30. $grade = trim($grade);
  31. $color = $this->input->post('color',true);
  32. $color = trim($color);
  33. $lowe = $this->input->post('lowe',true);
  34. $lowe = trim($lowe);
  35. $lacetype = $this->input->post('lacetype',true);
  36. $lacetype = trim($lacetype);
  37. $lacecolor = $this->input->post('lacecolor',true);
  38. $lacecolor = trim($lacecolor);
  39. $size = $this->input->post('size',true);
  40. $size = trim($size);
  41. $density = $this->input->post('density',true);
  42. $density = trim($density);
  43. $haircap = $this->input->post('haircap',true);
  44. $haircap = trim($haircap);
  45. $hairnumber = $this->input->post('hairnumber',true);
  46. $hairnumber = trim($hairnumber);
  47. if(empty($page))
  48. {
  49. $start = 0;
  50. $perpage = 1;
  51. }
  52. else
  53. {
  54. $start = ($page - 1)*$perpage;
  55. }
  56. $this->db->select('g.id, g.features, g.title, g.sku, g.zh, g.jm,g.has_source,g.update_time, gi.id as img_id, gi.source_cont');
  57. $this->db->from('crowd_goods as g');
  58. $this->db->join('crowd_goodimgs as gi', 'g.id = gi.goods_id', 'left');
  59. if($title){
  60. $title = trim($title);
  61. $this->db->like('g.title', $title);
  62. }
  63. if($zh){
  64. $zh = trim($zh);
  65. $this->db->like('g.zh', $zh);
  66. }
  67. if($sku){
  68. $sku = trim($sku);
  69. $this->db->like('g.sku', $sku);
  70. }
  71. if($category){
  72. $category = trim($category);
  73. $this->db->like('g.features', $category);
  74. }
  75. if($grade){
  76. $grade = trim($grade);
  77. $this->db->like('g.features', $grade);
  78. }
  79. if($color){
  80. $color = trim($color);
  81. $this->db->like('g.features', $color);
  82. }
  83. if($lowe){
  84. $lowe = trim($lowe);
  85. $this->db->like('g.features', $lowe);
  86. }
  87. if($lacetype){
  88. $lacetype = trim($lacetype);
  89. $this->db->like('g.features', $lacetype);
  90. }
  91. if($lacecolor){
  92. $lacecolor = trim($lacecolor);
  93. $this->db->like('g.features', $lacecolor);
  94. }
  95. if($size){
  96. $size = trim($size);
  97. $this->db->like('g.features', $size);
  98. }
  99. if($density){
  100. $density = trim($density);
  101. $this->db->like('g.features', $density);
  102. }
  103. if($haircap){
  104. $haircap = trim($haircap);
  105. $this->db->like('g.features', $haircap);
  106. }
  107. if($hairnumber){
  108. $hairnumber = trim($hairnumber);
  109. $this->db->like('g.features', $hairnumber);
  110. }
  111. $this->db->order_by('g.has_source', 'desc');
  112. $this->db->order_by('g.update_time', 'desc');
  113. $this->db->order_by('g.id', 'asc');
  114. // 分页 (limit, offset)
  115. $this->db->limit($perpage, $start);
  116. $query = $this->db->get();
  117. $list = $query->result_array();
  118. $info_list = [];
  119. foreach($list as $k => $v){
  120. $info_list[$k]['id'] = $v['id'];
  121. $info_list[$k]['sku'] = $v['sku'];
  122. $info_list[$k]['title'] = $v['title'];
  123. $info_list[$k]['zh'] = $v['zh'];
  124. $info_list[$k]['update_time'] = empty($v['update_time'])? '' : date('Y-m-d H:i',$v['update_time']);
  125. $info_list[$k]['imgs'] = $this->transimg($v['source_cont']);
  126. }
  127. $this->db->from('crowd_goods');
  128. if($title){
  129. $title = trim($title);
  130. $this->db->like('title', $title);
  131. }
  132. if($zh){
  133. $zh = trim($zh);
  134. $this->db->like('zh', $zh);
  135. }
  136. if($sku){
  137. $sku = trim($sku);
  138. $this->db->like('sku', $sku);
  139. }
  140. if($category){
  141. $category = trim($category);
  142. $this->db->like('features', $category);
  143. }
  144. if($grade){
  145. $grade = trim($grade);
  146. $this->db->like('features', $grade);
  147. }
  148. if($color){
  149. $color = trim($color);
  150. $this->db->like('features', $color);
  151. }
  152. if($lowe){
  153. $lowe = trim($lowe);
  154. $this->db->like('features', $lowe);
  155. }
  156. if($lacetype){
  157. $lacetype = trim($lacetype);
  158. $this->db->like('features', $lacetype);
  159. }
  160. if($lacecolor){
  161. $lacecolor = trim($lacecolor);
  162. $this->db->like('features', $lacecolor);
  163. }
  164. if($size){
  165. $size = trim($size);
  166. $this->db->like('features', $size);
  167. }
  168. if($density){
  169. $density = trim($density);
  170. $this->db->like('features', $density);
  171. }
  172. if($haircap){
  173. $haircap = trim($haircap);
  174. $this->db->like('features', $haircap);
  175. }
  176. if($hairnumber){
  177. $hairnumber = trim($hairnumber);
  178. $this->db->like('features', $hairnumber);
  179. }
  180. $total = $this->db->count_all_results();
  181. $pagenum = ceil($total/$perpage);
  182. $over = $total-($start+$perpage);
  183. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  184. echo json_encode($rows);exit;
  185. }else{
  186. $this->_Template('goodimglibrary',$this->data);
  187. }
  188. }
  189. private function transimg($source_cont){
  190. $str = ' ';
  191. if(!empty($source_cont)){
  192. $imgs = json_decode($source_cont,true);
  193. foreach($imgs as $k => $v){
  194. $type = $this->_checkVideo($v);
  195. $url = $this->_transingurl($v);
  196. if($type == "video"){
  197. $str.= '<video controls="true" width="100" src="'.$url.'" alt="video image" style="margin-right:3px;"></video>';
  198. }else{
  199. $str .= '<img width="100px" src="'.$url.'" alt="image" style="margin-right:3px;" onclick="showBigImg(this)">';
  200. }
  201. }
  202. }
  203. return$str;
  204. }
  205. private function _editData($arg_array){
  206. if($this->input->method() == 'post'){
  207. $id = $this->input->post('id',true);
  208. $img = $this->input->post('img',true);
  209. if(empty($img)){
  210. $img = [];
  211. }
  212. foreach($img as $k => $v){
  213. $img[$k] = str_replace($this->show_url, '', $v);
  214. }
  215. $info = $this->db->get_where('crowd_goods',array('id'=>$id))->row_array();
  216. $images = $this->goodimgs->find("goods_id = ".$id);
  217. $has_source = empty($img)?0:5;
  218. $update_time = time();
  219. if(empty($images)){
  220. if($this->goodimgs->insert(array('goods_id'=>$id,'features'=>$info['features'],'source_cont'=>json_encode($img,JSON_UNESCAPED_SLASHES)))){
  221. $this->goods->save(array('has_source'=>$has_source,'update_time'=>$update_time),$id);
  222. echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
  223. }else{
  224. echo json_encode(array('msg'=>'修改失败,请重试1','success'=>false));exit;
  225. }
  226. }else{
  227. if($this->goodimgs->save(array('features'=>$info['features'],'source_cont'=>json_encode($img,JSON_UNESCAPED_SLASHES)),$images['id'])){
  228. $this->goods->save(array('has_source'=>$has_source,'update_time'=>$update_time),$id);
  229. echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
  230. }else{
  231. echo json_encode(array('msg'=>'修改失败,请重试2','success'=>false));exit;
  232. }
  233. }
  234. }
  235. if($this->input->method() == 'get'){
  236. $id = $arg_array[0];
  237. $goods = $this->db->get_where('crowd_goods',array('id'=>$id))->row_array();
  238. $this->db->where('goods_id',$id);
  239. $images = $this->db->get('crowd_goodimgs')->result_array();
  240. if(empty($images)){
  241. $goods['images'] = [];
  242. }else{
  243. $imgs = json_decode($images[0]['source_cont'],true);
  244. $final_imgs = [];
  245. foreach($imgs as $k => $v){
  246. $final_imgs[$k]['url'] = $this->_transingurl($v);
  247. $final_imgs[$k]['type'] = $this->_checkVideo($v);
  248. }
  249. $goods['images'] = $final_imgs;
  250. }
  251. $this->data['goods'] = $goods;
  252. $this->_Template('goodimglibrary_edit',$this->data);
  253. }
  254. }
  255. //根据后缀判断是否是视频
  256. private function _checkVideo($str){
  257. $hz_arr = explode(".",$str);
  258. $hz = end($hz_arr);
  259. if(in_array($hz,['mp4','flv','rmvb','avi','wmv','mov','rm','mkv'])){
  260. return "video";
  261. }
  262. return "img";
  263. }
  264. private function _transingurl($url){
  265. $url_arr = explode('/', $url);
  266. $filename = array_pop($url_arr);
  267. $filename = rawurlencode($filename);
  268. $url_arr[] = $filename;
  269. $final_url = implode('/', $url_arr);
  270. $final_url = $this->show_url.$final_url;
  271. return $final_url;
  272. }
  273. }