Goodimglibrary.php 14 KB

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