Goodimglibrary.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805
  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. $this->load->_model("Model_typeclass","typeclass");
  13. $this->load->_model("Model_settingtest","settingtest");
  14. $this->load->_model("Model_apiyyv1","apiyyv1");
  15. }
  16. private $show_url = "https://lyerposs.wepolicy.cn";
  17. public function _remap($arg,$arg_array)
  18. {
  19. if($arg=="detail"){
  20. //$this->_detial($arg_array);
  21. }elseif($arg=="edit"){
  22. $this->_editData($arg_array);
  23. }elseif($arg == "get_info_number"){
  24. $this->_getInfoNumber();
  25. }elseif($arg == 'showsku'){
  26. $this->_showSku($arg_array);
  27. }elseif($arg == 'bcedit'){
  28. $this->_bcedit($arg_array);
  29. }elseif($arg == 'indexnoimg'){
  30. $this->_indexnoimg();
  31. }elseif($arg == 'add'){
  32. $this->_add();
  33. }elseif($arg == 'selectgood'){
  34. $this->_selectgood();
  35. }elseif($arg == 'getgoodbyids'){
  36. $this->_getgoodbyids();
  37. }else{
  38. $this->_index();
  39. }
  40. }
  41. private function _index(){
  42. if($this->input->method() == 'post'){
  43. $page = $this->input->post('page',true);
  44. $perpage = $this->input->post('perpage',true);
  45. $title = $this->input->post('title',true);
  46. $zh= $this->input->post('zh',true);
  47. $sku = $this->input->post('sku',true);
  48. $category = $this->input->post('category',true);
  49. $category = trim($category);
  50. $grade = $this->input->post('grade',true);
  51. $grade = trim($grade);
  52. $color = $this->input->post('color',true);
  53. $color = trim($color);
  54. $lowe = $this->input->post('lowe',true);
  55. $lowe = trim($lowe);
  56. $lacetype = $this->input->post('lacetype',true);
  57. $lacetype = trim($lacetype);
  58. $lacecolor = $this->input->post('lacecolor',true);
  59. $lacecolor = trim($lacecolor);
  60. $size = $this->input->post('size',true);
  61. $size = trim($size);
  62. $density = $this->input->post('density',true);
  63. $density = trim($density);
  64. $haircap = $this->input->post('haircap',true);
  65. $haircap = trim($haircap);
  66. $hairnumber = $this->input->post('hairnumber',true);
  67. $hairnumber = trim($hairnumber);
  68. if(empty($page))
  69. {
  70. $start = 0;
  71. $perpage = 1;
  72. }
  73. else
  74. {
  75. $start = ($page - 1)*$perpage;
  76. }
  77. $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');
  78. $this->db->from('crowd_goods as g');
  79. $this->db->join('crowd_goodimgs as gi', 'g.id = gi.goods_id', 'left');
  80. if($title){
  81. $title = trim($title);
  82. $this->db->like('g.title', $title);
  83. }
  84. if($zh){
  85. $zh = trim($zh);
  86. $this->db->like('g.zh', $zh);
  87. }
  88. if($sku){
  89. $sku = trim($sku);
  90. $this->db->like('g.sku', $sku);
  91. }
  92. if($category){
  93. $category = trim($category);
  94. $this->db->like('g.features', $category);
  95. }
  96. if($grade){
  97. $grade = trim($grade);
  98. $this->db->like('g.features', $grade);
  99. }
  100. if($color){
  101. $color = trim($color);
  102. $this->db->like('g.features', $color);
  103. }
  104. if($lowe){
  105. $lowe = trim($lowe);
  106. $this->db->like('g.features', $lowe);
  107. }
  108. if($lacetype){
  109. $lacetype = trim($lacetype);
  110. $this->db->like('g.features', $lacetype);
  111. }
  112. if($lacecolor){
  113. $lacecolor = trim($lacecolor);
  114. $this->db->like('g.features', $lacecolor);
  115. }
  116. if($size){
  117. $size = trim($size);
  118. $this->db->like('g.features', $size);
  119. }
  120. if($density){
  121. $density = trim($density);
  122. $this->db->like('g.features', $density);
  123. }
  124. if($haircap){
  125. $haircap = trim($haircap);
  126. $this->db->like('g.features', $haircap);
  127. }
  128. if($hairnumber){
  129. $hairnumber = trim($hairnumber);
  130. $this->db->like('g.features', $hairnumber);
  131. }
  132. $this->db->order_by('g.has_source', 'desc');
  133. $this->db->order_by('g.update_time', 'desc');
  134. $this->db->order_by('g.id', 'asc');
  135. // 分页 (limit, offset)
  136. $this->db->limit($perpage, $start);
  137. $query = $this->db->get();
  138. $list = $query->result_array();
  139. $info_list = [];
  140. foreach($list as $k => $v){
  141. $info_list[$k]['id'] = $v['id'];
  142. $info_list[$k]['sku'] = $v['sku'];
  143. $info_list[$k]['title'] = $v['title'];
  144. $info_list[$k]['zh'] = $v['zh'];
  145. $info_list[$k]['update_time'] = empty($v['update_time'])? '' : date('Y-m-d H:i',$v['update_time']);
  146. $info_list[$k]['imgs'] = $this->transimg($v['source_cont']);
  147. }
  148. $this->db->from('crowd_goods');
  149. if($title){
  150. $title = trim($title);
  151. $this->db->like('title', $title);
  152. }
  153. if($zh){
  154. $zh = trim($zh);
  155. $this->db->like('zh', $zh);
  156. }
  157. if($sku){
  158. $sku = trim($sku);
  159. $this->db->like('sku', $sku);
  160. }
  161. if($category){
  162. $category = trim($category);
  163. $this->db->like('features', $category);
  164. }
  165. if($grade){
  166. $grade = trim($grade);
  167. $this->db->like('features', $grade);
  168. }
  169. if($color){
  170. $color = trim($color);
  171. $this->db->like('features', $color);
  172. }
  173. if($lowe){
  174. $lowe = trim($lowe);
  175. $this->db->like('features', $lowe);
  176. }
  177. if($lacetype){
  178. $lacetype = trim($lacetype);
  179. $this->db->like('features', $lacetype);
  180. }
  181. if($lacecolor){
  182. $lacecolor = trim($lacecolor);
  183. $this->db->like('features', $lacecolor);
  184. }
  185. if($size){
  186. $size = trim($size);
  187. $this->db->like('features', $size);
  188. }
  189. if($density){
  190. $density = trim($density);
  191. $this->db->like('features', $density);
  192. }
  193. if($haircap){
  194. $haircap = trim($haircap);
  195. $this->db->like('features', $haircap);
  196. }
  197. if($hairnumber){
  198. $hairnumber = trim($hairnumber);
  199. $this->db->like('features', $hairnumber);
  200. }
  201. $total = $this->db->count_all_results();
  202. $pagenum = ceil($total/$perpage);
  203. $over = $total-($start+$perpage);
  204. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  205. echo json_encode($rows);exit;
  206. }else{
  207. $this->_Template('goodimglibrary',$this->data);
  208. }
  209. }
  210. private function _add(){
  211. if($this->input->method() == 'post'){
  212. $post = $this->input->post(null,true);
  213. if(empty($post['category'])){
  214. echo json_encode(['success' => false,'msg' => '请选择分类']);exit;
  215. }
  216. if($post['category'] != '131' && empty($post['size'])){
  217. echo json_encode(['success' => false,'msg' => '请选择尺寸']);exit;
  218. }
  219. if(isset($post['size'])){
  220. $post['size'] = trim($post['size'],",");
  221. }
  222. $typeclass = $this->logic_u9tools->getTypeClass();
  223. $classid = $this->logic_u9tools->getClass();
  224. $scsku = $classid;
  225. foreach($post as $k=>$v){
  226. if (!empty($v)) {
  227. $type_info = $this->typeclass->read($v);
  228. $scsku[$type_info['classid']] = $type_info['bqsku'];
  229. }
  230. }
  231. $scsku = implode("-", $scsku);
  232. $scsku = str_replace('- ', '-', trim($scsku, '-'));
  233. $scsku = str_replace(array('--------', '-------', '------', '-----', '----', '---', '--'), '-', $scsku);
  234. $res = $this->logic_zhlp->sortByName($post);
  235. if($res['code'] != 1){
  236. echo json_encode(['success' => false,'msg' => $res['msg']]);exit;
  237. }
  238. if(empty($res)){
  239. echo json_encode(['success' => false,'msg' => '分类异常']);exit;
  240. }
  241. $final_list = $res['data'];
  242. $tmp_arr = array_values($final_list);
  243. $size = array_pop($tmp_arr);
  244. $sku_tmp_arr = [];
  245. foreach($tmp_arr as $k=>$v){
  246. if($k == 1 && (!isset($final_list['hairtype']))){
  247. $sku_tmp_arr[] = $v;
  248. $sku_tmp_arr[] = $size;
  249. }
  250. elseif($k == 2 && (isset($final_list['hairtype']))){
  251. $sku_tmp_arr[] = $v;
  252. $sku_tmp_arr[] = $size;
  253. }else{
  254. $sku_tmp_arr[] = $v;
  255. }
  256. }
  257. $en_title = "";
  258. foreach($post as $k=>$v){
  259. if(in_array($v,[163,164,165,166])){
  260. continue;
  261. }
  262. if(isset($typeclass[$v])){
  263. $en_title.= $typeclass[$v]['title']." ";
  264. }
  265. }
  266. $en_title = trim($en_title);
  267. $sku = "-".implode("-",$sku_tmp_arr)."-";
  268. $org_sku = implode("-",$final_list);
  269. $u9_info = $this->logic_u9tools->getOneU9bmHasGift($org_sku,$classid,$typeclass);
  270. $u9_info['title'] = $en_title;
  271. $u9_info['sku'] = $scsku;
  272. $u9_info['features'] = $sku;
  273. $u9_info['org_sku'] = $org_sku;
  274. $r = $this->goods->find("features = '".$u9_info['features']."'");
  275. if(!empty($r)){
  276. if($r['u9_check'] != 1){
  277. //查询u9是否存在
  278. $u9_jm = $this->_getU9GoodInfoByJm($r['jm']);
  279. if(empty($u9_jm)){
  280. echo json_encode(['success' => false,'msg' => $r['jm'].':未同步到u9系统,请联系管理员同步到u9系统。']);exit;
  281. }else{
  282. $this->goods->save([
  283. 'u9_check'=>1,
  284. 'jm'=>$u9_jm
  285. ],$r['id']);
  286. }
  287. }
  288. echo json_encode(['success' => false,'msg' => '商品已录入']);exit;
  289. }
  290. //u9已经创建 但是erp没创建
  291. $u9_jm = $this->_getU9GoodInfoByJm($u9_info['jm']);
  292. if(!empty($u9_jm)){
  293. $rr = $this->goods->insert([
  294. 'features'=>$u9_info['features'],
  295. 'title'=>$u9_info['title'],
  296. 'sku'=>$u9_info['sku'],
  297. 'zh'=>$u9_info['zh'],
  298. 'jm'=>$u9_jm,
  299. 'u9_check'=>1,
  300. ]);
  301. if($rr){
  302. echo json_encode(['success' => true,'msg' => '商品添加成功']);
  303. exit;
  304. }else{
  305. echo json_encode(['success' => false,'msg' => '商品添加失败']);
  306. exit;
  307. }
  308. }
  309. $info = [
  310. 'jm'=>$u9_info['jm'],
  311. 'zh'=>$u9_info['zh'],
  312. 'bm'=>$u9_info['bm'],
  313. 'ztcode'=>'001',
  314. 'title'=>$u9_info['title'],
  315. 'owner_code'=>120,
  316. ];
  317. //u9没创建 erp也没有创建
  318. $token = $this->settingtest->get_yytoken_120();
  319. $res = $this->apiyyv1->cjLpAndtbLp($info,$token);
  320. if(empty($res[0]['Data'])){
  321. echo $res[0]['ResMsg'];
  322. exit;
  323. }
  324. if(empty($res[0]['Data'][0])){
  325. echo $res[0]['ResMsg'];
  326. exit;
  327. }
  328. if(!empty($res[0]['Data'][0]['ResMsg'])){
  329. echo $res[0]['Data'][0]['ResMsg'];
  330. exit;
  331. }
  332. $token = $this->settingtest->get_yytoken_120();
  333. $res = $this->apiyyv1->tbLpNew($info,$token);
  334. $rr = $this->goods->insert([
  335. 'features'=>$u9_info['features'],
  336. 'title'=>$u9_info['title'],
  337. 'sku'=>$u9_info['sku'],
  338. 'zh'=>$u9_info['zh'],
  339. 'jm'=>$u9_info['jm'],
  340. 'u9_check'=>1,
  341. ]);
  342. if($rr){
  343. echo json_encode(['success' => true,'msg' => '商品添加成功']);
  344. exit;
  345. }else{
  346. echo json_encode(['success' => false,'msg' => '商品添加失败']);
  347. exit;
  348. }
  349. }else{
  350. $this->data['data'] = "";
  351. $this->_Template('goodimglibrary_add',$this->data);
  352. }
  353. }
  354. private function _getU9GoodInfoByJm($jm){
  355. $u9_jm = "";
  356. //查询u9是否存在
  357. $token = $this->settingtest->get_yytoken_120();
  358. $res = $this->apiyyv1->cxLpByJm($jm,$token);
  359. if(!empty($res['Data'])){
  360. if(!empty($res['Data']['0'])){
  361. if(!empty($res['Data']['0']['m_code'])){
  362. $u9_jm = $res['Data']['0']['m_code'];
  363. }
  364. }
  365. }
  366. return $u9_jm;
  367. }
  368. private function _indexnoimg(){
  369. if($this->input->method() == 'post'){
  370. $page = $this->input->post('page',true);
  371. $perpage = $this->input->post('perpage',true);
  372. $title = $this->input->post('title',true);
  373. $zh= $this->input->post('zh',true);
  374. $sku = $this->input->post('sku',true);
  375. $category = $this->input->post('category',true);
  376. $category = trim($category);
  377. $grade = $this->input->post('grade',true);
  378. $grade = trim($grade);
  379. $color = $this->input->post('color',true);
  380. $color = trim($color);
  381. $lowe = $this->input->post('lowe',true);
  382. $lowe = trim($lowe);
  383. $lacetype = $this->input->post('lacetype',true);
  384. $lacetype = trim($lacetype);
  385. $lacecolor = $this->input->post('lacecolor',true);
  386. $lacecolor = trim($lacecolor);
  387. $size = $this->input->post('size',true);
  388. $size = trim($size);
  389. $density = $this->input->post('density',true);
  390. $density = trim($density);
  391. $haircap = $this->input->post('haircap',true);
  392. $haircap = trim($haircap);
  393. $hairnumber = $this->input->post('hairnumber',true);
  394. $hairnumber = trim($hairnumber);
  395. if(empty($page))
  396. {
  397. $start = 0;
  398. $perpage = 1;
  399. }
  400. else
  401. {
  402. $start = ($page - 1)*$perpage;
  403. }
  404. $where = '1 = 1';
  405. if($title){
  406. $title = trim($title);
  407. $where .= ' AND title LIKE "%'.trim($title).'%" ';
  408. }
  409. if($zh){
  410. $zh = trim($zh);
  411. $where .= ' AND zh LIKE "%'.trim($zh).'%" ';
  412. }
  413. if($sku){
  414. $sku = trim($sku);
  415. $where .= ' AND sku LIKE "%'.trim($sku).'%" ';
  416. }
  417. if($category){
  418. $category = trim($category);
  419. $where .= ' AND features LIKE "%'.trim($category).'%" ';
  420. }
  421. if($grade){
  422. $grade = trim($grade);
  423. $where .= ' AND features LIKE "%'.trim($grade).'%" ';
  424. }
  425. if($color){
  426. $color = trim($color);
  427. $where .= ' AND features LIKE "%'.trim($color).'%" ';
  428. }
  429. if($lowe){
  430. $lowe = trim($lowe);
  431. $where .= ' AND features LIKE "%'.trim($lowe).'%" ';
  432. }
  433. if($lacetype){
  434. $lacetype = trim($lacetype);
  435. $where .= ' AND features LIKE "%'.trim($lacetype).'%" ';
  436. }
  437. if($lacecolor){
  438. $lacecolor = trim($lacecolor);
  439. $where .= ' AND features LIKE "%'.trim($lacecolor).'%" ';
  440. }
  441. if($size){
  442. $size = trim($size);
  443. $where .= ' AND features LIKE "%'.trim($size).'%" ';
  444. }
  445. if($density){
  446. $density = trim($density);
  447. $where .= ' AND features LIKE "%'.trim($density).'%" ';
  448. }
  449. if($haircap){
  450. $haircap = trim($haircap);
  451. $where .= ' AND features LIKE "%'.trim($haircap).'%" ';
  452. }
  453. if($hairnumber){
  454. $hairnumber = trim($hairnumber);
  455. $where .= ' AND features LIKE "%'.trim($hairnumber).'%" ';
  456. }
  457. $list = $this->goods->find_all($where,'id,sku,title,zh,jm,update_time','id DESC',$start,$perpage);
  458. $info_list = [];
  459. foreach($list as $k => $v){
  460. $info_list[$k]['id'] = $v['id'];
  461. $info_list[$k]['sku'] = $v['sku']." <i class='fa fa-copy' data-text='".$v['sku']."' onclick='fuzhi(this)' style='background-color:#FFE4C4'></i>";
  462. $info_list[$k]['title'] = $v['title']." <i class='fa fa-copy' data-text='".$v['title']."' onclick='fuzhi(this)' style='background-color:#FFE4C4'></i>";
  463. $info_list[$k]['zh'] = $v['zh']." <i class='fa fa-copy' data-text='".$v['zh']."' onclick='fuzhi(this)' style='background-color:#FFE4C4'></i>";
  464. $info_list[$k]['jm'] = $v['jm']." <i class='fa fa-copy' data-text='".$v['jm']."' onclick='fuzhi(this)' style='background-color:#FFE4C4'></i>";
  465. }
  466. $total = $this->goods->find_count($where);
  467. $pagenum = ceil($total/$perpage);
  468. $over = $total-($start+$perpage);
  469. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  470. echo json_encode($rows);exit;
  471. }else{
  472. $user = $this->user->get_api($_SESSION['api']);
  473. $user_id = $user['id'];
  474. $this->data['user_id'] = $user_id;
  475. $this->_Template('goodimglibrary_noimg',$this->data);
  476. }
  477. }
  478. private function transimg($source_cont){
  479. $str = ' ';
  480. if(!empty($source_cont)){
  481. $imgs = json_decode($source_cont,true);
  482. foreach($imgs as $k => $v){
  483. $type = $this->_checkVideo($v);
  484. $url = $this->_transingurl($v);
  485. if($type == "video"){
  486. $str.= '<video controls="true" width="100" src="'.$url.'" alt="video image" style="margin-right:3px;"></video>';
  487. }else{
  488. $str .= '<img width="100px" src="'.$url.'" alt="image" style="margin-right:3px;" onclick="showBigImg(this)">';
  489. }
  490. }
  491. }
  492. return $str;
  493. }
  494. private function _editData($arg_array){
  495. if($this->input->method() == 'post'){
  496. $id = $this->input->post('id',true);
  497. $img = $this->input->post('img',true);
  498. if(empty($img)){
  499. $img = [];
  500. }
  501. foreach($img as $k => $v){
  502. $img[$k] = str_replace($this->show_url, '', $v);
  503. }
  504. $info = $this->db->get_where('crowd_goods',array('id'=>$id))->row_array();
  505. $images = $this->goodimgs->find("goods_id = ".$id);
  506. $has_source = empty($img)?0:5;
  507. $update_time = time();
  508. if(empty($images)){
  509. if($this->goodimgs->insert(array('goods_id'=>$id,'features'=>$info['features'],'source_cont'=>json_encode($img,JSON_UNESCAPED_SLASHES)))){
  510. $this->goods->save(array('has_source'=>$has_source,'update_time'=>$update_time),$id);
  511. echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
  512. }else{
  513. echo json_encode(array('msg'=>'修改失败,请重试1','success'=>false));exit;
  514. }
  515. }else{
  516. if($this->goodimgs->save(array('features'=>$info['features'],'source_cont'=>json_encode($img,JSON_UNESCAPED_SLASHES)),$images['id'])){
  517. $this->goods->save(array('has_source'=>$has_source,'update_time'=>$update_time),$id);
  518. echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
  519. }else{
  520. echo json_encode(array('msg'=>'修改失败,请重试2','success'=>false));exit;
  521. }
  522. }
  523. }
  524. if($this->input->method() == 'get'){
  525. $id = $arg_array[0];
  526. $goods = $this->db->get_where('crowd_goods',array('id'=>$id))->row_array();
  527. $this->db->where('goods_id',$id);
  528. $images = $this->db->get('crowd_goodimgs')->result_array();
  529. if(empty($images)){
  530. $goods['images'] = [];
  531. }else{
  532. $imgs = json_decode($images[0]['source_cont'],true);
  533. $final_imgs = [];
  534. foreach($imgs as $k => $v){
  535. $final_imgs[$k]['url'] = $this->_transingurl($v);
  536. $final_imgs[$k]['type'] = $this->_checkVideo($v);
  537. }
  538. $goods['images'] = $final_imgs;
  539. }
  540. $this->data['goods'] = $goods;
  541. $this->_Template('goodimglibrary_edit',$this->data);
  542. }
  543. }
  544. private function _bcedit($arg_array){
  545. if($this->input->method() == 'post'){
  546. $id = $this->input->post('id',true);
  547. $img = $this->input->post('img',true);
  548. if(empty($img)){
  549. $img = [];
  550. }
  551. foreach($img as $k => $v){
  552. $img[$k] = str_replace($this->show_url, '', $v);
  553. }
  554. $info = $this->db->get_where('crowd_goods',array('id'=>$id))->row_array();
  555. $images = $this->goodimgs->find("goods_id = ".$id);
  556. $has_source = empty($img)?0:5;
  557. $update_time = time();
  558. if(empty($images)){
  559. if($this->goodimgs->insert(array('goods_id'=>$id,'features'=>$info['features'],'source_cont'=>json_encode($img,JSON_UNESCAPED_SLASHES)))){
  560. $this->goods->save(array('has_source'=>$has_source,'update_time'=>$update_time),$id);
  561. echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
  562. }else{
  563. echo json_encode(array('msg'=>'修改失败,请重试1','success'=>false));exit;
  564. }
  565. }else{
  566. if($this->goodimgs->save(array('features'=>$info['features'],'source_cont'=>json_encode($img,JSON_UNESCAPED_SLASHES)),$images['id'])){
  567. $this->goods->save(array('has_source'=>$has_source,'update_time'=>$update_time),$id);
  568. echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
  569. }else{
  570. echo json_encode(array('msg'=>'修改失败,请重试3','success'=>false));exit;
  571. }
  572. }
  573. }
  574. if($this->input->method() == 'get'){
  575. $id = $arg_array[0];
  576. $goods = $this->db->get_where('crowd_goods',array('id'=>$id))->row_array();
  577. $this->db->where('goods_id',$id);
  578. $images = $this->db->get('crowd_goodimgs')->result_array();
  579. if(empty($images)){
  580. $goods['images'] = [];
  581. }else{
  582. $imgs = json_decode($images[0]['source_cont'],true);
  583. $final_imgs = [];
  584. foreach($imgs as $k => $v){
  585. $final_imgs[$k]['url'] = $this->_transingurl($v);
  586. $final_imgs[$k]['type'] = $this->_checkVideo($v);
  587. }
  588. $goods['images'] = $final_imgs;
  589. }
  590. $this->data['goods'] = $goods;
  591. $this->_Template('goodimglibrary_bcedit',$this->data);
  592. }
  593. }
  594. //根据后缀判断是否是视频
  595. private function _checkVideo($str){
  596. $hz_arr = explode(".",$str);
  597. $hz = end($hz_arr);
  598. if(in_array($hz,['mp4','flv','rmvb','avi','wmv','mov','rm','mkv'])){
  599. return "video";
  600. }
  601. return "img";
  602. }
  603. private function _transingurl($url){
  604. $url_arr = explode('/', $url);
  605. $filename = array_pop($url_arr);
  606. $filename = rawurlencode($filename);
  607. $url_arr[] = $filename;
  608. $final_url = implode('/', $url_arr);
  609. $final_url = $this->show_url.$final_url;
  610. return $final_url;
  611. }
  612. public function _getInfoNumber(){
  613. if($this->input->method() == 'post'){
  614. $number = $this->input->post('number',true);
  615. if(empty($number)){
  616. echo json_encode(['msg'=>'请输入订单编码','success'=>false,'data'=>[]]);exit;
  617. }
  618. $info = $this->logic_order->getInfo("number = '$number'");
  619. if(empty($info)){
  620. echo json_encode(['msg'=>'订单信息不存在','success'=>false,'data'=>[]]);exit;
  621. }
  622. $fpdata = $info['fpdata'];
  623. $tmp_list = explode(';', trim($fpdata,';'));
  624. $sku_list = [];
  625. foreach($tmp_list as $k => $v){
  626. $tmp_arr = explode('|', $v);
  627. if(strpos($tmp_arr[0],',') !== false){
  628. $tmp_arr[0] =
  629. $sku_list[] = $this->logic_u9tools->getGoodFeatureAlone($tmp_arr[0]);
  630. }else{
  631. $sku_list[] = "-".trim($tmp_arr[0],"-")."-";
  632. }
  633. }
  634. $final_list = [];
  635. $classid = $this->logic_u9tools->getClass();
  636. $typeclass = $this->logic_u9tools->getTypeClass();
  637. foreach($sku_list as $k => $v){
  638. if(strpos($v,'-131-') !== false){
  639. continue;
  640. }
  641. $r = $this->logic_zhlp->transferSku(explode('-',trim($v,'-')));
  642. $rr = $this->logic_zhlp->sortByColume($r);
  643. $rrr = $this->logic_zhlp->featureTransferColumn($rr['data'],$classid);
  644. $rrrr = $this->logic_u9tools->getOneU9bmHasGift($v,$classid,$typeclass);
  645. $final_list[] = [
  646. 'jm'=>$rrrr['jm'],
  647. 'zh'=>$rrrr['zh'],
  648. 'sku'=>$rrr['sku'],
  649. 'title'=>$rrr['title'],
  650. 'zzh'=>$rrr['zh'],
  651. 'features'=>$v,
  652. ];
  653. }
  654. foreach($final_list as $k => $v){
  655. $info = $this->goods->find("features = '$v[features]'");
  656. if(!empty($info)){
  657. $final_list[$k]['s_id'] = $info['id'];
  658. }else{
  659. $id = $this->goods->insert([
  660. 'features'=>$v['features'],
  661. 'title'=>$v['title'],
  662. 'zh'=>$v['zh'],
  663. 'sku'=>$v['sku'],
  664. 'jm'=>$v['jm'],
  665. ]);
  666. $final_list[$k]['s_id'] = $id;
  667. $final_list[$k]['has_source'] = 0;
  668. }
  669. }
  670. echo json_encode(['msg'=>'订单信息获取成功','success'=>true,'data'=>$final_list]);exit;
  671. }else{
  672. $this->_Template('goodimglibrary_number',$this->data);
  673. }
  674. }
  675. private function _showSku($arg_array){
  676. echo "<pre>";
  677. print_r($arg_array);
  678. die;
  679. }
  680. private function _selectgood(){
  681. if($this->input->method() == 'post'){
  682. $params = $this->input->post(null,true);
  683. $this->db->select('id,features, title, sku, zh, jm');
  684. $this->db->from('crowd_goods');
  685. $category = $params['category'];
  686. $this->db->like('features',$category);
  687. if(!empty($params['color'])){
  688. $this->db->like('features',$params['color']);
  689. }
  690. if(!empty($params['density'])){
  691. $this->db->like('features',$params['density']);
  692. }
  693. if(!empty($params['grade'])){
  694. $this->db->like('features',$params['grade']);
  695. }
  696. if(!empty($params['haircap'])){
  697. $this->db->like('features',$params['haircap']);
  698. }
  699. if(!empty($params['hairnumber'])){
  700. $this->db->like('features',$params['hairnumber']);
  701. }
  702. if(!empty($params['lacecolor'])){
  703. $this->db->like('features',$params['lacecolor']);
  704. }
  705. if(!empty($params['lacetype'])){
  706. $this->db->like('features',$params['lacetype']);
  707. }
  708. if(!empty($params['lowe'])){
  709. $this->db->like('features',$params['lowe']);
  710. }
  711. if(!empty($params['size'])){
  712. $this->db->like('features',$params['size']);
  713. }
  714. if(!empty($params['zh'])){
  715. $this->db->like('zh',$params['zh']);
  716. }
  717. $this->db->order_by('id', 'asc');
  718. // 分页 (limit, offset)
  719. $this->db->limit(20, 0);
  720. $query = $this->db->get();
  721. $list = $query->result_array();
  722. if(empty($list)){
  723. echo json_encode(['success'=>false,'msg'=>'查询失败']);exit;
  724. }else{
  725. echo json_encode(['success'=>true,'msg'=>'查询成功','data'=>$list]);exit;
  726. }
  727. }else{
  728. $this->_Template('goodimglibrary_selectgood',$this->data);
  729. }
  730. }
  731. private function _getgoodbyids(){
  732. if($this->input->method() == 'post'){
  733. $ids = $this->input->post('ids',true);
  734. $this->db->select('id,features, title, sku, zh, jm');
  735. $this->db->from('crowd_goods');
  736. $this->db->where_in('id',$ids);
  737. $query = $this->db->get();
  738. $list = $query->result_array();
  739. echo json_encode(['success'=>true,'msg'=>'查询成功','data'=>$list]);exit;
  740. }else{
  741. echo json_encode(['success'=>false,'msg'=>'查询失败']);exit;
  742. }
  743. }
  744. }