Goodimglibrary.php 37 KB

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