Goodimglibrary.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  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. $this->load->_model('Model_logic_order','logic_order');
  9. $this->load->_model("Model_logic_zhlp","logic_zhlp");
  10. $this->load->_model("Model_classid","classid");
  11. $this->load->_model("Model_logic_u9tools","logic_u9tools");
  12. }
  13. private $show_url = "https://lyerposs.wepolicy.cn";
  14. public function _remap($arg,$arg_array)
  15. {
  16. if($arg=="detail"){
  17. //$this->_detial($arg_array);
  18. }elseif($arg=="edit"){
  19. $this->_editData($arg_array);
  20. }elseif($arg == "get_info_number"){
  21. $this->_getInfoNumber();
  22. }elseif($arg == 'showsku'){
  23. $this->_showSku($arg_array);
  24. }elseif($arg == 'bcedit'){
  25. $this->_bcedit($arg_array);
  26. }else{
  27. $this->_index();
  28. }
  29. }
  30. private function _index(){
  31. if($this->input->method() == 'post'){
  32. $page = $this->input->post('page',true);
  33. $perpage = $this->input->post('perpage',true);
  34. $title = $this->input->post('title',true);
  35. $zh= $this->input->post('zh',true);
  36. $sku = $this->input->post('sku',true);
  37. $category = $this->input->post('category',true);
  38. $category = trim($category);
  39. $grade = $this->input->post('grade',true);
  40. $grade = trim($grade);
  41. $color = $this->input->post('color',true);
  42. $color = trim($color);
  43. $lowe = $this->input->post('lowe',true);
  44. $lowe = trim($lowe);
  45. $lacetype = $this->input->post('lacetype',true);
  46. $lacetype = trim($lacetype);
  47. $lacecolor = $this->input->post('lacecolor',true);
  48. $lacecolor = trim($lacecolor);
  49. $size = $this->input->post('size',true);
  50. $size = trim($size);
  51. $density = $this->input->post('density',true);
  52. $density = trim($density);
  53. $haircap = $this->input->post('haircap',true);
  54. $haircap = trim($haircap);
  55. $hairnumber = $this->input->post('hairnumber',true);
  56. $hairnumber = trim($hairnumber);
  57. if(empty($page))
  58. {
  59. $start = 0;
  60. $perpage = 1;
  61. }
  62. else
  63. {
  64. $start = ($page - 1)*$perpage;
  65. }
  66. $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');
  67. $this->db->from('crowd_goods as g');
  68. $this->db->join('crowd_goodimgs as gi', 'g.id = gi.goods_id', 'left');
  69. if($title){
  70. $title = trim($title);
  71. $this->db->like('g.title', $title);
  72. }
  73. if($zh){
  74. $zh = trim($zh);
  75. $this->db->like('g.zh', $zh);
  76. }
  77. if($sku){
  78. $sku = trim($sku);
  79. $this->db->like('g.sku', $sku);
  80. }
  81. if($category){
  82. $category = trim($category);
  83. $this->db->like('g.features', $category);
  84. }
  85. if($grade){
  86. $grade = trim($grade);
  87. $this->db->like('g.features', $grade);
  88. }
  89. if($color){
  90. $color = trim($color);
  91. $this->db->like('g.features', $color);
  92. }
  93. if($lowe){
  94. $lowe = trim($lowe);
  95. $this->db->like('g.features', $lowe);
  96. }
  97. if($lacetype){
  98. $lacetype = trim($lacetype);
  99. $this->db->like('g.features', $lacetype);
  100. }
  101. if($lacecolor){
  102. $lacecolor = trim($lacecolor);
  103. $this->db->like('g.features', $lacecolor);
  104. }
  105. if($size){
  106. $size = trim($size);
  107. $this->db->like('g.features', $size);
  108. }
  109. if($density){
  110. $density = trim($density);
  111. $this->db->like('g.features', $density);
  112. }
  113. if($haircap){
  114. $haircap = trim($haircap);
  115. $this->db->like('g.features', $haircap);
  116. }
  117. if($hairnumber){
  118. $hairnumber = trim($hairnumber);
  119. $this->db->like('g.features', $hairnumber);
  120. }
  121. $this->db->order_by('g.has_source', 'desc');
  122. $this->db->order_by('g.update_time', 'desc');
  123. $this->db->order_by('g.id', 'asc');
  124. // 分页 (limit, offset)
  125. $this->db->limit($perpage, $start);
  126. $query = $this->db->get();
  127. $list = $query->result_array();
  128. $info_list = [];
  129. foreach($list as $k => $v){
  130. $info_list[$k]['id'] = $v['id'];
  131. $info_list[$k]['sku'] = $v['sku'];
  132. $info_list[$k]['title'] = $v['title'];
  133. $info_list[$k]['zh'] = $v['zh'];
  134. $info_list[$k]['update_time'] = empty($v['update_time'])? '' : date('Y-m-d H:i',$v['update_time']);
  135. $info_list[$k]['imgs'] = $this->transimg($v['source_cont']);
  136. }
  137. $this->db->from('crowd_goods');
  138. if($title){
  139. $title = trim($title);
  140. $this->db->like('title', $title);
  141. }
  142. if($zh){
  143. $zh = trim($zh);
  144. $this->db->like('zh', $zh);
  145. }
  146. if($sku){
  147. $sku = trim($sku);
  148. $this->db->like('sku', $sku);
  149. }
  150. if($category){
  151. $category = trim($category);
  152. $this->db->like('features', $category);
  153. }
  154. if($grade){
  155. $grade = trim($grade);
  156. $this->db->like('features', $grade);
  157. }
  158. if($color){
  159. $color = trim($color);
  160. $this->db->like('features', $color);
  161. }
  162. if($lowe){
  163. $lowe = trim($lowe);
  164. $this->db->like('features', $lowe);
  165. }
  166. if($lacetype){
  167. $lacetype = trim($lacetype);
  168. $this->db->like('features', $lacetype);
  169. }
  170. if($lacecolor){
  171. $lacecolor = trim($lacecolor);
  172. $this->db->like('features', $lacecolor);
  173. }
  174. if($size){
  175. $size = trim($size);
  176. $this->db->like('features', $size);
  177. }
  178. if($density){
  179. $density = trim($density);
  180. $this->db->like('features', $density);
  181. }
  182. if($haircap){
  183. $haircap = trim($haircap);
  184. $this->db->like('features', $haircap);
  185. }
  186. if($hairnumber){
  187. $hairnumber = trim($hairnumber);
  188. $this->db->like('features', $hairnumber);
  189. }
  190. $total = $this->db->count_all_results();
  191. $pagenum = ceil($total/$perpage);
  192. $over = $total-($start+$perpage);
  193. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  194. echo json_encode($rows);exit;
  195. }else{
  196. $this->_Template('goodimglibrary',$this->data);
  197. }
  198. }
  199. private function transimg($source_cont){
  200. $str = ' ';
  201. if(!empty($source_cont)){
  202. $imgs = json_decode($source_cont,true);
  203. foreach($imgs as $k => $v){
  204. $type = $this->_checkVideo($v);
  205. $url = $this->_transingurl($v);
  206. if($type == "video"){
  207. $str.= '<video controls="true" width="100" src="'.$url.'" alt="video image" style="margin-right:3px;"></video>';
  208. }else{
  209. $str .= '<img width="100px" src="'.$url.'" alt="image" style="margin-right:3px;" onclick="showBigImg(this)">';
  210. }
  211. }
  212. }
  213. return$str;
  214. }
  215. private function _editData($arg_array){
  216. if($this->input->method() == 'post'){
  217. $id = $this->input->post('id',true);
  218. $img = $this->input->post('img',true);
  219. if(empty($img)){
  220. $img = [];
  221. }
  222. foreach($img as $k => $v){
  223. $img[$k] = str_replace($this->show_url, '', $v);
  224. }
  225. $info = $this->db->get_where('crowd_goods',array('id'=>$id))->row_array();
  226. $images = $this->goodimgs->find("goods_id = ".$id);
  227. $has_source = empty($img)?0:5;
  228. $update_time = time();
  229. if(empty($images)){
  230. if($this->goodimgs->insert(array('goods_id'=>$id,'features'=>$info['features'],'source_cont'=>json_encode($img,JSON_UNESCAPED_SLASHES)))){
  231. $this->goods->save(array('has_source'=>$has_source,'update_time'=>$update_time),$id);
  232. echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
  233. }else{
  234. echo json_encode(array('msg'=>'修改失败,请重试1','success'=>false));exit;
  235. }
  236. }else{
  237. if($this->goodimgs->save(array('features'=>$info['features'],'source_cont'=>json_encode($img,JSON_UNESCAPED_SLASHES)),$images['id'])){
  238. $this->goods->save(array('has_source'=>$has_source,'update_time'=>$update_time),$id);
  239. echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
  240. }else{
  241. echo json_encode(array('msg'=>'修改失败,请重试2','success'=>false));exit;
  242. }
  243. }
  244. }
  245. if($this->input->method() == 'get'){
  246. $id = $arg_array[0];
  247. $goods = $this->db->get_where('crowd_goods',array('id'=>$id))->row_array();
  248. $this->db->where('goods_id',$id);
  249. $images = $this->db->get('crowd_goodimgs')->result_array();
  250. if(empty($images)){
  251. $goods['images'] = [];
  252. }else{
  253. $imgs = json_decode($images[0]['source_cont'],true);
  254. $final_imgs = [];
  255. foreach($imgs as $k => $v){
  256. $final_imgs[$k]['url'] = $this->_transingurl($v);
  257. $final_imgs[$k]['type'] = $this->_checkVideo($v);
  258. }
  259. $goods['images'] = $final_imgs;
  260. }
  261. $this->data['goods'] = $goods;
  262. $this->_Template('goodimglibrary_edit',$this->data);
  263. }
  264. }
  265. private function _bcedit($arg_array){
  266. if($this->input->method() == 'post'){
  267. $id = $this->input->post('id',true);
  268. $img = $this->input->post('img',true);
  269. if(empty($img)){
  270. $img = [];
  271. }
  272. foreach($img as $k => $v){
  273. $img[$k] = str_replace($this->show_url, '', $v);
  274. }
  275. $info = $this->db->get_where('crowd_goods',array('id'=>$id))->row_array();
  276. $images = $this->goodimgs->find("goods_id = ".$id);
  277. $has_source = empty($img)?0:5;
  278. $update_time = time();
  279. if(empty($images)){
  280. if($this->goodimgs->insert(array('goods_id'=>$id,'features'=>$info['features'],'source_cont'=>json_encode($img,JSON_UNESCAPED_SLASHES)))){
  281. $this->goods->save(array('has_source'=>$has_source,'update_time'=>$update_time),$id);
  282. echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
  283. }else{
  284. echo json_encode(array('msg'=>'修改失败,请重试1','success'=>false));exit;
  285. }
  286. }else{
  287. if($this->goodimgs->save(array('features'=>$info['features'],'source_cont'=>json_encode($img,JSON_UNESCAPED_SLASHES)),$images['id'])){
  288. $this->goods->save(array('has_source'=>$has_source,'update_time'=>$update_time),$id);
  289. echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
  290. }else{
  291. echo json_encode(array('msg'=>'修改失败,请重试3','success'=>false));exit;
  292. }
  293. }
  294. }
  295. if($this->input->method() == 'get'){
  296. $id = $arg_array[0];
  297. $goods = $this->db->get_where('crowd_goods',array('id'=>$id))->row_array();
  298. $this->db->where('goods_id',$id);
  299. $images = $this->db->get('crowd_goodimgs')->result_array();
  300. if(empty($images)){
  301. $goods['images'] = [];
  302. }else{
  303. $imgs = json_decode($images[0]['source_cont'],true);
  304. $final_imgs = [];
  305. foreach($imgs as $k => $v){
  306. $final_imgs[$k]['url'] = $this->_transingurl($v);
  307. $final_imgs[$k]['type'] = $this->_checkVideo($v);
  308. }
  309. $goods['images'] = $final_imgs;
  310. }
  311. $this->data['goods'] = $goods;
  312. $this->_Template('goodimglibrary_bcedit',$this->data);
  313. }
  314. }
  315. //根据后缀判断是否是视频
  316. private function _checkVideo($str){
  317. $hz_arr = explode(".",$str);
  318. $hz = end($hz_arr);
  319. if(in_array($hz,['mp4','flv','rmvb','avi','wmv','mov','rm','mkv'])){
  320. return "video";
  321. }
  322. return "img";
  323. }
  324. private function _transingurl($url){
  325. $url_arr = explode('/', $url);
  326. $filename = array_pop($url_arr);
  327. $filename = rawurlencode($filename);
  328. $url_arr[] = $filename;
  329. $final_url = implode('/', $url_arr);
  330. $final_url = $this->show_url.$final_url;
  331. return $final_url;
  332. }
  333. public function _getInfoNumber(){
  334. if($this->input->method() == 'post'){
  335. $number = $this->input->post('number',true);
  336. if(empty($number)){
  337. echo json_encode(['msg'=>'请输入订单编码','success'=>false,'data'=>[]]);exit;
  338. }
  339. $info = $this->logic_order->getInfo("number = '$number'");
  340. if(empty($info)){
  341. echo json_encode(['msg'=>'订单信息不存在','success'=>false,'data'=>[]]);exit;
  342. }
  343. $fpdata = $info['fpdata'];
  344. $tmp_list = explode(';', trim($fpdata,';'));
  345. $sku_list = [];
  346. foreach($tmp_list as $k => $v){
  347. $tmp_arr = explode('|', $v);
  348. if(strpos($tmp_arr[0],',') !== false){
  349. $tmp_arr[0] =
  350. $sku_list[] = $this->logic_u9tools->getGoodFeatureAlone($tmp_arr[0]);
  351. }else{
  352. $sku_list[] = "-".trim($tmp_arr[0],"-")."-";
  353. }
  354. }
  355. $final_list = [];
  356. $classid = $this->logic_u9tools->getClass();
  357. $typeclass = $this->logic_u9tools->getTypeClass();
  358. foreach($sku_list as $k => $v){
  359. if(strpos($v,'-131-') !== false){
  360. continue;
  361. }
  362. $r = $this->logic_zhlp->transferSku(explode('-',trim($v,'-')));
  363. $rr = $this->logic_zhlp->sortByColume($r);
  364. $rrr = $this->logic_zhlp->featureTransferColumn($rr['data'],$classid);
  365. $rrrr = $this->logic_u9tools->getOneU9bmHasGift($v,$classid,$typeclass);
  366. $final_list[] = [
  367. 'jm'=>$rrrr['jm'],
  368. 'zh'=>$rrrr['zh'],
  369. 'sku'=>$rrr['sku'],
  370. 'title'=>$rrr['title'],
  371. 'zzh'=>$rrr['zh'],
  372. 'features'=>$v,
  373. ];
  374. }
  375. foreach($final_list as $k => $v){
  376. $info = $this->goods->find("features = '$v[features]'");
  377. if(!empty($info)){
  378. $final_list[$k]['s_id'] = $info['id'];
  379. }else{
  380. $id = $this->goods->insert([
  381. 'features'=>$v['features'],
  382. 'title'=>$v['title'],
  383. 'zh'=>$v['zh'],
  384. 'sku'=>$v['sku'],
  385. 'jm'=>$v['jm'],
  386. ]);
  387. $final_list[$k]['s_id'] = $id;
  388. }
  389. }
  390. echo json_encode(['msg'=>'订单信息获取成功','success'=>true,'data'=>$final_list]);exit;
  391. }else{
  392. $this->_Template('goodimglibrary_number',$this->data);
  393. }
  394. }
  395. private function _showSku($arg_array){
  396. echo "<pre>";
  397. print_r($arg_array);
  398. die;
  399. }
  400. }