Goodimglibrary.php 10 KB

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