Goodimglibrary.php 39 KB

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