Goodimglibrary.php 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987
  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. $type_info = $this->typeclass->read($v);
  245. $scsku[$type_info['classid']] = $type_info['bqsku'];
  246. }
  247. }
  248. $scsku = implode("-", $scsku);
  249. $scsku = str_replace('- ', '-', trim($scsku, '-'));
  250. $scsku = str_replace(array('--------', '-------', '------', '-----', '----', '---', '--'), '-', $scsku);
  251. $tmp_arr = array_values($final_list);
  252. $size = array_pop($tmp_arr);
  253. $sku_tmp_arr = [];
  254. foreach($tmp_arr as $k=>$v){
  255. if($k == 1 && (!isset($final_list['hairtype']))){
  256. $sku_tmp_arr[] = $v;
  257. $sku_tmp_arr[] = $size;
  258. }
  259. elseif($k == 2 && (isset($final_list['hairtype']))){
  260. $sku_tmp_arr[] = $v;
  261. $sku_tmp_arr[] = $size;
  262. }else{
  263. $sku_tmp_arr[] = $v;
  264. }
  265. }
  266. $en_title = "";
  267. foreach($final_list as $k=>$v){
  268. if(in_array($v,[163,164,165,166])){
  269. continue;
  270. }
  271. if(isset($typeclass[$v])){
  272. $en_title.= $typeclass[$v]['title']." ";
  273. }
  274. }
  275. $en_title = trim($en_title);
  276. $sku = "-".implode("-",$sku_tmp_arr)."-";
  277. $org_sku = implode("-",$final_list);
  278. $u9_info = $this->logic_u9tools->getOneU9bmHasGift($org_sku,$classid,$typeclass);
  279. $u9_info['title'] = $en_title;
  280. $u9_info['sku'] = $scsku;
  281. $u9_info['features'] = $sku;
  282. $u9_info['org_sku'] = $org_sku;
  283. $r = $this->goods->find("features = '".$u9_info['features']."'");
  284. if(!empty($r)){
  285. if($r['u9_check'] != 1){
  286. //查询u9是否存在
  287. $u9_jm = $this->_getU9GoodInfoByJm($r['jm']);
  288. if(empty($u9_jm)){
  289. echo json_encode(['success' => false,'msg' => $r['jm'].':未同步到u9系统,请联系管理员同步到u9系统。'.json_encode($u9_jm)]);exit;
  290. }else{
  291. $this->goods->save([
  292. 'u9_check'=>1,
  293. 'jm'=>$u9_jm
  294. ],$r['id']);
  295. }
  296. }
  297. echo json_encode(['success' => false,'msg' => '商品已录入']);exit;
  298. }
  299. //u9已经创建 但是erp没创建
  300. $u9_jm = $this->_getU9GoodInfoByJm($u9_info['jm']);
  301. if(!empty($u9_jm)){
  302. $rr = $this->goods->insert([
  303. 'features'=>$u9_info['features'],
  304. 'title'=>$u9_info['title'],
  305. 'sku'=>$u9_info['sku'],
  306. 'zh'=>$u9_info['zh'],
  307. 'jm'=>$u9_jm,
  308. 'u9_check'=>1,
  309. ]);
  310. if($rr){
  311. echo json_encode(['success' => true,'msg' => '商品添加成功']);
  312. exit;
  313. }else{
  314. echo json_encode(['success' => false,'msg' => '商品添加失败']);
  315. exit;
  316. }
  317. }
  318. $info = [
  319. 'jm'=>$u9_info['jm'],
  320. 'zh'=>$u9_info['zh'],
  321. 'bm'=>$u9_info['bm'],
  322. 'ztcode'=>'001',
  323. 'title'=>$u9_info['title'],
  324. 'owner_code'=>120,
  325. ];
  326. //u9没创建 erp也没有创建
  327. $token = $this->settingtest->get_yytoken_120();
  328. $res = $this->apiyyv1->cjLpAndtbLp($info,$token);
  329. if(empty($res[0]['Data'])){
  330. echo $res[0]['ResMsg'];
  331. exit;
  332. }
  333. if(empty($res[0]['Data'][0])){
  334. echo $res[0]['ResMsg'];
  335. exit;
  336. }
  337. if(!empty($res[0]['Data'][0]['ResMsg'])){
  338. echo $res[0]['Data'][0]['ResMsg'];
  339. exit;
  340. }
  341. $token = $this->settingtest->get_yytoken_120();
  342. $res = $this->apiyyv1->tbLpNew($info,$token);
  343. $rr = $this->goods->insert([
  344. 'features'=>$u9_info['features'],
  345. 'title'=>$u9_info['title'],
  346. 'sku'=>$u9_info['sku'],
  347. 'zh'=>$u9_info['zh'],
  348. 'jm'=>$u9_info['jm'],
  349. 'u9_check'=>1,
  350. ]);
  351. if($rr){
  352. echo json_encode(['success' => true,'msg' => '商品添加成功']);
  353. exit;
  354. }else{
  355. echo json_encode(['success' => false,'msg' => '商品添加失败']);
  356. exit;
  357. }
  358. }else{
  359. $this->data['data'] = "";
  360. $this->_Template('goodimglibrary_add',$this->data);
  361. }
  362. }
  363. private function _getU9GoodInfoByJm($jm){
  364. $u9_jm = "";
  365. //查询u9是否存在
  366. $token = $this->settingtest->get_yytoken_120();
  367. $res = $this->apiyyv1->cxLpByJm($jm,$token);
  368. if(!empty($res['Data'])){
  369. if(!empty($res['Data']['0'])){
  370. if(!empty($res['Data']['0']['m_code'])){
  371. $u9_jm = $res['Data']['0']['m_code'];
  372. }
  373. }
  374. }
  375. return $u9_jm;
  376. }
  377. private function _indexnoimg(){
  378. $user = $this->user->get_api($_SESSION['api']);
  379. $user_id = $user['id'];
  380. if($this->input->method() == 'post'){
  381. $page = $this->input->post('page',true);
  382. $perpage = $this->input->post('perpage',true);
  383. $title = $this->input->post('title',true);
  384. $zh= $this->input->post('zh',true);
  385. $sku = $this->input->post('sku',true);
  386. $category = $this->input->post('category',true);
  387. $category = trim($category);
  388. $grade = $this->input->post('grade',true);
  389. $grade = trim($grade);
  390. $color = $this->input->post('color',true);
  391. $color = trim($color);
  392. $lowe = $this->input->post('lowe',true);
  393. $lowe = trim($lowe);
  394. $lacetype = $this->input->post('lacetype',true);
  395. $lacetype = trim($lacetype);
  396. $lacecolor = $this->input->post('lacecolor',true);
  397. $lacecolor = trim($lacecolor);
  398. $size = $this->input->post('size',true);
  399. $size = trim($size);
  400. $density = $this->input->post('density',true);
  401. $density = trim($density);
  402. $haircap = $this->input->post('haircap',true);
  403. $haircap = trim($haircap);
  404. $hairnumber = $this->input->post('hairnumber',true);
  405. $hairnumber = trim($hairnumber);
  406. $jm = $this->input->post("jm",true);
  407. $kuwei_set = $this->input->post("kuwei_set",true);
  408. if(empty($page))
  409. {
  410. $start = 0;
  411. $perpage = 1;
  412. }
  413. else
  414. {
  415. $start = ($page - 1)*$perpage;
  416. }
  417. $where = '1 = 1';
  418. if($title){
  419. $title = trim($title);
  420. $where .= ' AND title LIKE "%'.trim($title).'%" ';
  421. }
  422. if($zh){
  423. $zh = trim($zh);
  424. $where .= ' AND zh LIKE "%'.trim($zh).'%" ';
  425. }
  426. if($sku){
  427. $sku = trim($sku);
  428. $where .= ' AND sku LIKE "%'.trim($sku).'%" ';
  429. }
  430. if($category){
  431. $category = trim($category);
  432. $where .= ' AND features LIKE "%'.trim($category).'%" ';
  433. }
  434. if($grade){
  435. $grade = trim($grade);
  436. $where .= ' AND features LIKE "%'.trim($grade).'%" ';
  437. }
  438. if($color){
  439. $color = trim($color);
  440. $where .= ' AND features LIKE "%'.trim($color).'%" ';
  441. }
  442. if($lowe){
  443. $lowe = trim($lowe);
  444. $where .= ' AND features LIKE "%'.trim($lowe).'%" ';
  445. }
  446. if($lacetype){
  447. $lacetype = trim($lacetype);
  448. $where .= ' AND features LIKE "%'.trim($lacetype).'%" ';
  449. }
  450. if($lacecolor){
  451. $lacecolor = trim($lacecolor);
  452. $where .= ' AND features LIKE "%'.trim($lacecolor).'%" ';
  453. }
  454. if($size){
  455. $size = trim($size);
  456. $where .= ' AND features LIKE "%'.trim($size).'%" ';
  457. }
  458. if($density){
  459. $density = trim($density);
  460. $where .= ' AND features LIKE "%'.trim($density).'%" ';
  461. }
  462. if($haircap){
  463. $haircap = trim($haircap);
  464. $where .= ' AND features LIKE "%'.trim($haircap).'%" ';
  465. }
  466. if($hairnumber){
  467. $hairnumber = trim($hairnumber);
  468. $where .= ' AND features LIKE "%'.trim($hairnumber).'%" ';
  469. }
  470. if($jm){
  471. $where .= ' AND jm LIKE "%'.trim($jm).'%" ';
  472. }
  473. if($kuwei_set > -1){
  474. $where .= ' AND kuwei_set = '.$kuwei_set.' ';
  475. }
  476. $is_able_edit = 0;
  477. if(in_array($user_id,[10,28])){
  478. $is_able_edit = 1;
  479. }
  480. $list = $this->goods->find_all($where,'id,sku,title,zh,jm,update_time,kuwei,old_sku','id DESC',$start,$perpage);
  481. $info_list = [];
  482. foreach($list as $k => $v){
  483. $info_list[$k]['id'] = $v['id'];
  484. if($is_able_edit == 1){
  485. $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><br/><b style='color:red'>".$v['old_sku']."</b>";
  486. }else{
  487. $info_list[$k]['sku'] = $v['sku']." <i class='fa fa-copy' data-text='".$v['sku']."' onclick='fuzhi(this)' style='background-color:#FFE4C4'></i><br/><b style='color:red'>".$v['old_sku']."</b>";
  488. }
  489. $info_list[$k]['title'] = $v['title']." <i class='fa fa-copy' data-text='".$v['title']."' onclick='fuzhi(this)' style='background-color:#FFE4C4'></i>";
  490. $info_list[$k]['zh'] = $v['zh']." <i class='fa fa-copy' data-text='".$v['zh']."' onclick='fuzhi(this)' style='background-color:#FFE4C4'></i>";
  491. $info_list[$k]['jm'] = $v['jm']." <i class='fa fa-copy' data-text='".$v['jm']."' onclick='fuzhi(this)' style='background-color:#FFE4C4'></i>";
  492. $kuwei = "";
  493. if(!empty($v['kuwei'])){
  494. $tmp_str = json_decode($v['kuwei'],true);
  495. if(!empty($tmp_str['xc'])){
  496. $kuwei = $tmp_str['xc'];
  497. }
  498. }
  499. $info_list[$k]['kuwei'] = " <i class='fa fa-edit' data-id ='".$v['id']."' data-kw='".$kuwei."' onclick='editkw(this)' style='color:red'></i> ".$kuwei;
  500. }
  501. $total = $this->goods->find_count($where);
  502. $pagenum = ceil($total/$perpage);
  503. $over = $total-($start+$perpage);
  504. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  505. echo json_encode($rows);exit;
  506. }else{
  507. $user = $this->user->get_api($_SESSION['api']);
  508. $user_id = $user['id'];
  509. $this->data['user_id'] = $user_id;
  510. $this->_Template('goodimglibrary_noimg',$this->data);
  511. }
  512. }
  513. private function transimg($source_cont){
  514. $str = ' ';
  515. if(!empty($source_cont)){
  516. $imgs = json_decode($source_cont,true);
  517. foreach($imgs as $k => $v){
  518. $type = $this->_checkVideo($v);
  519. $url = $this->_transingurl($v);
  520. if($type == "video"){
  521. $str.= '<video controls="true" width="100" src="'.$url.'" alt="video image" style="margin-right:3px;"></video>';
  522. }else{
  523. $str .= '<img width="100px" src="'.$url.'" alt="image" style="margin-right:3px;" onclick="showBigImg(this)">';
  524. }
  525. }
  526. }
  527. return $str;
  528. }
  529. private function _editData($arg_array){
  530. if($this->input->method() == 'post'){
  531. $id = $this->input->post('id',true);
  532. $img = $this->input->post('img',true);
  533. if(empty($img)){
  534. $img = [];
  535. }
  536. foreach($img as $k => $v){
  537. $img[$k] = str_replace($this->show_url, '', $v);
  538. }
  539. $info = $this->db->get_where('crowd_goods',array('id'=>$id))->row_array();
  540. $images = $this->goodimgs->find("goods_id = ".$id);
  541. $has_source = empty($img)?0:5;
  542. $update_time = time();
  543. if(empty($images)){
  544. if($this->goodimgs->insert(array('goods_id'=>$id,'features'=>$info['features'],'source_cont'=>json_encode($img,JSON_UNESCAPED_SLASHES)))){
  545. $this->goods->save(array('has_source'=>$has_source,'update_time'=>$update_time),$id);
  546. echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
  547. }else{
  548. echo json_encode(array('msg'=>'修改失败,请重试1','success'=>false));exit;
  549. }
  550. }else{
  551. if($this->goodimgs->save(array('features'=>$info['features'],'source_cont'=>json_encode($img,JSON_UNESCAPED_SLASHES)),$images['id'])){
  552. $this->goods->save(array('has_source'=>$has_source,'update_time'=>$update_time),$id);
  553. echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
  554. }else{
  555. echo json_encode(array('msg'=>'修改失败,请重试2','success'=>false));exit;
  556. }
  557. }
  558. }
  559. if($this->input->method() == 'get'){
  560. $id = $arg_array[0];
  561. $goods = $this->db->get_where('crowd_goods',array('id'=>$id))->row_array();
  562. $this->db->where('goods_id',$id);
  563. $images = $this->db->get('crowd_goodimgs')->result_array();
  564. if(empty($images)){
  565. $goods['images'] = [];
  566. }else{
  567. $imgs = json_decode($images[0]['source_cont'],true);
  568. $final_imgs = [];
  569. foreach($imgs as $k => $v){
  570. $final_imgs[$k]['url'] = $this->_transingurl($v);
  571. $final_imgs[$k]['type'] = $this->_checkVideo($v);
  572. }
  573. $goods['images'] = $final_imgs;
  574. }
  575. $this->data['goods'] = $goods;
  576. $this->_Template('goodimglibrary_edit',$this->data);
  577. }
  578. }
  579. private function _bcedit($arg_array){
  580. if($this->input->method() == 'post'){
  581. $id = $this->input->post('id',true);
  582. $img = $this->input->post('img',true);
  583. if(empty($img)){
  584. $img = [];
  585. }
  586. foreach($img as $k => $v){
  587. $img[$k] = str_replace($this->show_url, '', $v);
  588. }
  589. $info = $this->db->get_where('crowd_goods',array('id'=>$id))->row_array();
  590. $images = $this->goodimgs->find("goods_id = ".$id);
  591. $has_source = empty($img)?0:5;
  592. $update_time = time();
  593. if(empty($images)){
  594. if($this->goodimgs->insert(array('goods_id'=>$id,'features'=>$info['features'],'source_cont'=>json_encode($img,JSON_UNESCAPED_SLASHES)))){
  595. $this->goods->save(array('has_source'=>$has_source,'update_time'=>$update_time),$id);
  596. echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
  597. }else{
  598. echo json_encode(array('msg'=>'修改失败,请重试1','success'=>false));exit;
  599. }
  600. }else{
  601. if($this->goodimgs->save(array('features'=>$info['features'],'source_cont'=>json_encode($img,JSON_UNESCAPED_SLASHES)),$images['id'])){
  602. $this->goods->save(array('has_source'=>$has_source,'update_time'=>$update_time),$id);
  603. echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
  604. }else{
  605. echo json_encode(array('msg'=>'修改失败,请重试3','success'=>false));exit;
  606. }
  607. }
  608. }
  609. if($this->input->method() == 'get'){
  610. $id = $arg_array[0];
  611. $goods = $this->db->get_where('crowd_goods',array('id'=>$id))->row_array();
  612. $this->db->where('goods_id',$id);
  613. $images = $this->db->get('crowd_goodimgs')->result_array();
  614. if(empty($images)){
  615. $goods['images'] = [];
  616. }else{
  617. $imgs = json_decode($images[0]['source_cont'],true);
  618. $final_imgs = [];
  619. foreach($imgs as $k => $v){
  620. $final_imgs[$k]['url'] = $this->_transingurl($v);
  621. $final_imgs[$k]['type'] = $this->_checkVideo($v);
  622. }
  623. $goods['images'] = $final_imgs;
  624. }
  625. $this->data['goods'] = $goods;
  626. $this->_Template('goodimglibrary_bcedit',$this->data);
  627. }
  628. }
  629. //根据后缀判断是否是视频
  630. private function _checkVideo($str){
  631. $hz_arr = explode(".",$str);
  632. $hz = end($hz_arr);
  633. $hz = strtolower($hz);
  634. if(in_array($hz,['mp4','flv','rmvb','avi','wmv','mov','rm','mkv'])){
  635. return "video";
  636. }
  637. return "img";
  638. }
  639. private function _transingurl($url){
  640. $url_arr = explode('/', $url);
  641. $filename = array_pop($url_arr);
  642. $filename = rawurlencode($filename);
  643. $url_arr[] = $filename;
  644. $final_url = implode('/', $url_arr);
  645. $final_url = $this->show_url.$final_url;
  646. return $final_url;
  647. }
  648. public function _getInfoNumber(){
  649. if($this->input->method() == 'post'){
  650. $number = $this->input->post('number',true);
  651. if(empty($number)){
  652. echo json_encode(['msg'=>'请输入订单编码','success'=>false,'data'=>[]]);exit;
  653. }
  654. $info = $this->logic_order->getInfo("number = '$number'");
  655. if(empty($info)){
  656. echo json_encode(['msg'=>'订单信息不存在','success'=>false,'data'=>[]]);exit;
  657. }
  658. $fpdata = $info['fpdata'];
  659. $tmp_list = explode(';', trim($fpdata,';'));
  660. $sku_list = [];
  661. foreach($tmp_list as $k => $v){
  662. $tmp_arr = explode('|', $v);
  663. if(strpos($tmp_arr[0],',') !== false){
  664. $tmp_arr[0] =
  665. $sku_list[] = $this->logic_u9tools->getGoodFeatureAlone($tmp_arr[0]);
  666. }else{
  667. $sku_list[] = "-".trim($tmp_arr[0],"-")."-";
  668. }
  669. }
  670. $final_list = [];
  671. $classid = $this->logic_u9tools->getClass();
  672. $typeclass = $this->logic_u9tools->getTypeClass();
  673. foreach($sku_list as $k => $v){
  674. if(strpos($v,'-131-') !== false){
  675. continue;
  676. }
  677. $r = $this->logic_zhlp->transferSku(explode('-',trim($v,'-')));
  678. $rr = $this->logic_zhlp->sortByColume($r);
  679. $rrr = $this->logic_zhlp->featureTransferColumn($rr['data'],$classid);
  680. $rrrr = $this->logic_u9tools->getOneU9bmHasGift($v,$classid,$typeclass);
  681. $final_list[] = [
  682. 'jm'=>$rrrr['jm'],
  683. 'zh'=>$rrrr['zh'],
  684. 'sku'=>$rrr['sku'],
  685. 'title'=>$rrr['title'],
  686. 'zzh'=>$rrr['zh'],
  687. 'features'=>$v,
  688. ];
  689. }
  690. foreach($final_list as $k => $v){
  691. $info = $this->goods->find("features = '$v[features]'");
  692. if(!empty($info)){
  693. $final_list[$k]['s_id'] = $info['id'];
  694. }else{
  695. $id = $this->goods->insert([
  696. 'features'=>$v['features'],
  697. 'title'=>$v['title'],
  698. 'zh'=>$v['zh'],
  699. 'sku'=>$v['sku'],
  700. 'jm'=>$v['jm'],
  701. ]);
  702. $final_list[$k]['s_id'] = $id;
  703. $final_list[$k]['has_source'] = 0;
  704. }
  705. }
  706. echo json_encode(['msg'=>'订单信息获取成功','success'=>true,'data'=>$final_list]);exit;
  707. }else{
  708. $this->_Template('goodimglibrary_number',$this->data);
  709. }
  710. }
  711. private function _showSku($arg_array){
  712. echo "<pre>";
  713. print_r($arg_array);
  714. die;
  715. }
  716. private function _selectgood(){
  717. if($this->input->method() == 'post'){
  718. $params = $this->input->post(null,true);
  719. $this->db->select('id,features, title, sku, zh, jm');
  720. $this->db->from('crowd_goods');
  721. if(!empty($params['category'])){
  722. $this->db->like('features',$params['category']);
  723. }
  724. if(!empty($params['jm'])){
  725. $this->db->like('jm',$params['jm']);
  726. }
  727. if(!empty($params['color'])){
  728. $this->db->like('features',$params['color']);
  729. }
  730. if(!empty($params['density'])){
  731. $this->db->like('features',$params['density']);
  732. }
  733. if(!empty($params['grade'])){
  734. $this->db->like('features',$params['grade']);
  735. }
  736. if(!empty($params['haircap'])){
  737. $this->db->like('features',$params['haircap']);
  738. }
  739. if(!empty($params['hairnumber'])){
  740. $this->db->like('features',$params['hairnumber']);
  741. }
  742. if(!empty($params['lacecolor'])){
  743. $this->db->like('features',$params['lacecolor']);
  744. }
  745. if(!empty($params['lacetype'])){
  746. $this->db->like('features',$params['lacetype']);
  747. }
  748. if(!empty($params['lowe'])){
  749. $this->db->like('features',$params['lowe']);
  750. }
  751. if(!empty($params['size'])){
  752. $this->db->like('features',$params['size']);
  753. }
  754. if(!empty($params['zh'])){
  755. $this->db->like('zh',$params['zh']);
  756. }
  757. $this->db->order_by('id', 'asc');
  758. // 分页 (limit, offset)
  759. $this->db->limit(20, 0);
  760. $query = $this->db->get();
  761. $list = $query->result_array();
  762. if(empty($list)){
  763. echo json_encode(['success'=>false,'msg'=>'查询失败']);exit;
  764. }else{
  765. echo json_encode(['success'=>true,'msg'=>'查询成功','data'=>$list]);exit;
  766. }
  767. }else{
  768. $this->_Template('goodimglibrary_selectgood',$this->data);
  769. }
  770. }
  771. private function _getgoodbyids(){
  772. if($this->input->method() == 'post'){
  773. $ids = $this->input->post('ids',true);
  774. $this->db->select('id,features, title, sku, zh, jm');
  775. $this->db->from('crowd_goods');
  776. $this->db->where_in('id',$ids);
  777. $query = $this->db->get();
  778. $list = $query->result_array();
  779. echo json_encode(['success'=>true,'msg'=>'查询成功','data'=>$list]);exit;
  780. }else{
  781. echo json_encode(['success'=>false,'msg'=>'查询失败']);exit;
  782. }
  783. }
  784. private function _excelgood(){
  785. if($this->input->method() == 'post'){
  786. $params = $this->input->post(null,true);
  787. $this->db->select('features, title, sku, zh, jm');
  788. $this->db->from('crowd_goods');
  789. if(!empty($params['category'])){
  790. $this->db->like('features',$params['category']);
  791. }
  792. if(!empty($params['color'])){
  793. $this->db->like('features',$params['color']);
  794. }
  795. if(!empty($params['density'])){
  796. $this->db->like('features',$params['density']);
  797. }
  798. if(!empty($params['grade'])){
  799. $this->db->like('features',$params['grade']);
  800. }
  801. if(!empty($params['haircap'])){
  802. $this->db->like('features',$params['haircap']);
  803. }
  804. if(!empty($params['lacecolor'])){
  805. $this->db->like('features',$params['lacecolor']);
  806. }
  807. if(!empty($params['lacetype'])){
  808. $this->db->like('features',$params['lacetype']);
  809. }
  810. if(!empty($params['lowe'])){
  811. $this->db->like('features',$params['lowe']);
  812. }
  813. if(!empty($params['size'])){
  814. $this->db->like('features',$params['size']);
  815. }
  816. if(!empty($params['zh'])){
  817. $this->db->like('zh',$params['zh']);
  818. }
  819. if(!empty($params['sku'])){
  820. $this->db->like('sku',$params['sku']);
  821. }
  822. if(!empty($params['title'])){
  823. $this->db->like('title',$params['title']);
  824. }
  825. $query = $this->db->get();
  826. $list = $query->result_array();
  827. if(empty($list)){
  828. echo json_encode(['success'=>false,'msg'=>'没有数据']);exit;
  829. }else{
  830. $final_list = [];
  831. foreach($list as $k => $v){
  832. $final_list[] = [
  833. 'u9料号'=>$v['jm'],
  834. '仓库品名'=>$v['zh'],
  835. '英文名字'=>$v['title'],
  836. 'SKU'=>$v['sku'],
  837. ];
  838. }
  839. echo json_encode(['success'=>true,'msg'=>'查询成功','data'=>$final_list]);exit;
  840. }
  841. }else{
  842. echo json_encode(['success'=>false,'msg'=>'请求不合法']);exit;
  843. }
  844. }
  845. private function _editsku(){
  846. if($this->input->method() == 'post'){
  847. $id = $this->input->post('id',true);
  848. $sku = $this->input->post('sku',true);
  849. $info = $this->goods->read($id);
  850. if(empty($info)){
  851. echo json_encode(['success'=>false,'msg'=>'料品不存在']);exit;
  852. }
  853. if($info['sku'] == $sku){
  854. echo json_encode(['success'=>false,'msg'=>'料品SKU未变动']);exit;
  855. }
  856. if($this->goods->save(array('sku'=>$sku),$id)){
  857. echo json_encode(['success'=>true,'msg'=>'料品SKU修改成功']);exit;
  858. }else{
  859. echo json_encode(['success'=>false,'msg'=>'料品SKU修改失败']);exit;
  860. }
  861. }else{
  862. echo json_encode(['success'=>false,'msg'=>'请求不合法']);exit;
  863. }
  864. }
  865. private function _editkuwei(){
  866. if($this->input->method() == 'post'){
  867. $id = $this->input->post('id',true);
  868. $kuwei = $this->input->post('kuwei',true);
  869. $info = $this->goods->read($id);
  870. if(empty($info)){
  871. echo json_encode(['success'=>false,'msg'=>'料品不存在']);exit;
  872. }
  873. if($info['kuwei'] == $kuwei){
  874. echo json_encode(['success'=>false,'msg'=>'许昌仓库位未变动']);exit;
  875. }
  876. if($this->goods->save(array('kuwei'=>json_encode(['xc'=>$kuwei]),'kuwei_set'=>1),$id)){
  877. echo json_encode(['success'=>true,'msg'=>'许昌仓库位修改成功']);exit;
  878. }else{
  879. echo json_encode(['success'=>false,'msg'=>'许昌仓库位修改失败']);exit;
  880. }
  881. }else{
  882. echo json_encode(['success'=>false,'msg'=>'请求不合法']);exit;
  883. }
  884. }
  885. public function _jmbysku(){
  886. if($this->input->method() == 'post'){
  887. $jm = $this->input->post('jm',true);
  888. if(empty($jm)){
  889. echo json_encode(['success'=>false,'msg'=>'请求参数异常']);exit;
  890. }
  891. $info = $this->goods->find('jm = "'.$jm.'"');
  892. if(empty($info)){
  893. echo json_encode(['success'=>false,'msg'=>'料品不存在']);exit;
  894. }
  895. $features = $info['features'];
  896. $features_arr = explode("-",trim($features,"-"));
  897. $typeclass_list = $this->typeclass->find_all("id in (".implode(",",$features_arr).")");
  898. $features_arr = array_column($typeclass_list,'id','classid');
  899. $res = $this->logic_zhlp->sortByColume($features_arr);
  900. if($res['code'] != 1){
  901. echo json_encode(['success'=>false,'msg'=>$res["msg"]]);exit;
  902. }
  903. $classid = $this->logic_u9tools->getClass();
  904. $r = $this->logic_zhlp->featureTransferColumn($res['data'],$classid);
  905. $info = $this->whlabel->find("sku !='".$r['sku']."' and features = '".$features."' and warehouse = 13");
  906. if(!empty($info)){
  907. echo json_encode(['success'=>false,'msg'=>'系统生成sku和库存使用sku不一致联系技术处理']);exit;
  908. }
  909. echo json_encode(['success'=>true,'msg' =>$r['sku']]);
  910. }else{
  911. echo json_encode(['success'=>false,'msg'=>'请求不合法']);exit;
  912. }
  913. }
  914. }