Goodimglibrary.php 33 KB

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