Goodimglibrary.php 39 KB

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