Goodimglibrary.php 35 KB

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