Good.php 99 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875
  1. <?php
  2. namespace app\abutment\controller;
  3. use app\admin\model\ActionLog;
  4. use app\admin\model\ChangeLog;
  5. use app\admin\model\ProcessOrder;
  6. use app\youzan\model\PlatformYouzan;
  7. use think\facade\Db;
  8. //商品模块
  9. class Good extends HomeBaseController
  10. {
  11. private $gold = [1 => '18K', 2 => '24K', 3 => '白银'];
  12. //获取商品列表
  13. public function list()
  14. {
  15. $this->post = $this->request->filter('trim')->post();
  16. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
  17. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
  18. $where = [["gb.is_del", "=", 0], ['gb.is_stock', '=', 0]];
  19. $condit = [["a.is_del", "=", 0]];
  20. $cat_id = isset($this->post['cat_id']) && $this->post['cat_id'] !== "" ? intval($this->post['cat_id']) : "";
  21. if ($cat_id !== "") {
  22. $cat_ids = catChild($cat_id);
  23. $where[] = ['gb.cat_id', "in", $cat_ids];
  24. $condit[] = ['a.cat_id', "in", $cat_ids];
  25. }
  26. $good_name = isset($this->post['good_name']) && $this->post['good_name'] !== "" ? trim($this->post['good_name']) : "";
  27. if ($good_name !== "") {
  28. $where[] = ['gb.good_name', "like", "%$good_name%"];
  29. $condit[] = ['a.good_name', "like", "%$good_name%"];
  30. }
  31. $spucode = isset($this->post['spucode']) && $this->post['spucode'] !== "" ? trim($this->post['spucode']) : "";
  32. if ($spucode !== "") {
  33. $where[] = ['gb.spuCode', "like", "%$spucode%"];
  34. $condit[] = ['a.spuCode', "like", "%$spucode%"];
  35. }
  36. $good_type = isset($this->post['good_type']) && $this->post['good_type'] !== "" ? trim($this->post['good_type']) : "";
  37. if ($good_type !== "") {
  38. $where[] = ['gb.good_type', "=", $good_type];
  39. $condit[] = ['a.good_type', "=", $good_type];
  40. }
  41. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
  42. if ($companyNo !== "") {
  43. $where[] = ['gb.companyNo', "like", "%$companyNo%"];
  44. $condit[] = ['a.companyNo', "like", "%$companyNo%"];
  45. }
  46. $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] !== "" ? trim($this->post['supplierNo']) : "";
  47. if ($supplierNo !== "") {
  48. $where[] = ['gb.supplierNo', "like", "%$supplierNo%"];
  49. $condit[] = ['a.supplierNo', "like", "%$supplierNo%"];
  50. }
  51. $supplier = isset($this->post['supplier']) && $this->post['supplier'] !== "" ? trim($this->post['supplier']) : "";
  52. if ($supplier !== "") {
  53. $suppliernos = Db::name("supplier")->where([["name", "like", "%$supplier%"]])->column("code");
  54. $where[] = ['gb.supplierNo', "in", $suppliernos];
  55. $condit[] = ['a.supplierNo', "in", $suppliernos];
  56. }
  57. $company = isset($this->post['company']) && $this->post['company'] !== "" ? trim($this->post['company']) : "";
  58. if ($company !== "") {
  59. $companyNos = Db::name("business")->where([["company", "like", "%$company%"]])->column("companyNo");
  60. $where[] = ['gb.companyNo', "in", $companyNos];
  61. $condit[] = ['a.companyNo', "in", $companyNos];
  62. }
  63. $brandid = isset($this->post['brandid']) && $this->post['brandid'] !== "" ? intval($this->post['brandid']) : "";
  64. if ($brandid !== "") {
  65. $where[] = ['gb.brand_id', "=", $brandid];
  66. $condit[] = ['a.brand_id', "=", $brandid];
  67. }
  68. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  69. if ($status !== "") {
  70. $where[] = ['gb.status', "=", $status];
  71. $condit[] = ['a.status', "=", $status];
  72. }
  73. // $is_stock = isset($this->post['is_stock']) && $this->post['is_stock'] !== "" ? intval($this->post['is_stock']) : '';
  74. // if ($is_stock !== '') {
  75. // $where[] = ['gb.is_stock', "=", $is_stock];
  76. // }
  77. $start = isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start'] : "";
  78. if ($start !== "") {
  79. $where[] = ['gb.addtime', ">=", date('Y-m-d H:i:s', strtotime($start))];
  80. $condit[] = ['a.addtime', ">=", date('Y-m-d H:i:s', strtotime($start))];
  81. }
  82. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] : "";
  83. if ($end !== "") {
  84. $where[] = ['gb.addtime', "<", date('Y-m-d H:i:s', strtotime($end) + 24 * 3600)];
  85. $condit[] = ['a.addtime', "<", date('Y-m-d H:i:s', strtotime($end) + 24 * 3600)];
  86. }
  87. $isonline = isset($this->post['isonline']) && $this->post['isonline'] !== "" ? $this->post['isonline'] : "";
  88. if ($isonline !== "") {
  89. $condit[] = ['b.exam_status', "=", 6];
  90. // if($isonline==1){
  91. // $condit[] =['b.exam_status',"=",6];
  92. // }else{
  93. // $condit[] =['b.exam_status',"<>",6];
  94. // }
  95. $sta = Db::name("good_basic")
  96. ->alias("a")
  97. ->leftJoin("good_platform b", "a.spuCode=b.spuCode")
  98. ->where($condit)
  99. ->group("a.spuCode")
  100. ->column('a.spuCode');
  101. if ($isonline == 1) $where[] = ["gb.spuCode", "in", $sta];
  102. else $where[] = ["gb.spuCode", "not in", $sta];
  103. }
  104. // $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  105. // if($token==""){
  106. // return json_show(101,'token不能为空');
  107. // }
  108. // $apply_id =GetUserInfo($token);
  109. // if(empty($apply_id)||$apply_id['code']!=0){
  110. // return json_show(102,"申请人数据不存在");
  111. // }
  112. // $rm = $this->request->user['uid'];//isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  113. // $where[] = ['gb.createrid', "=", $rm];
  114. $where[] = ['gb.supplierNo', "=", $this->request->user['supplierNo']];
  115. // if($rm!=''){
  116. // $useinfo = Db::name("user_role")->where(['uid'=>$rm,"status"=>1,"is_del"=>0])->find();
  117. // if($useinfo==false){
  118. // return json_show(1002,"未找到用户角色权限");
  119. // }
  120. // $check = checkRole($useinfo['roleid'],115);
  121. // if($check){
  122. // $where[]=['gb.createrid', "=" ,$rm];
  123. // }
  124. // }
  125. // $role=$this->checkRole();
  126. // if(!empty($role['write'])){
  127. // $where[]=["gb.createrid","in",$role['write']];
  128. // }
  129. $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  130. if ($company_name !== "") $where[] = ["gb.createrid", 'in', get_company_item_user_by_name($company_name)];
  131. $count = Db::name('good_basic')->alias('gb')->where($where)->count();
  132. $total = ceil($count / $size);
  133. $page = $page >= $total ? $total : $page;
  134. $list = Db::name('good_basic')
  135. ->alias('gb')
  136. ->where($where)
  137. ->page($page, $size)
  138. ->order("addtime desc")
  139. ->select()
  140. ->toArray();
  141. $all_createrid = array_column($list,'chargerid');
  142. $item = get_company_name_by_uid($all_createrid);
  143. $data = [];
  144. //查询一下这些spucode是否在平台上成功上线
  145. $exam_statuss = Db::name('good_platform')
  146. ->whereIn('spuCode', array_column($list, 'spuCode'))
  147. ->where(['is_del' => 0, 'exam_status' => 3])//exam_status==3表示上线审核成功
  148. ->column('id', 'spuCode');
  149. $exam_status_yz = Db::name('platform_youzan')
  150. ->whereIn('spuCode', array_column($list, 'spuCode'))
  151. ->where(['is_del' => 0, 'exam_status' =>6])//exam_status==6表示上线审核成功
  152. ->column('id', 'spuCode');
  153. foreach ($list as $value) {
  154. $value["cat_info"] = made($value['cat_id'], []);
  155. $brand = Db::name("brand")->where(["id" => $value['brand_id']])->find();
  156. $value["brand_name"] = isset($brand['brand_name']) ? $brand['brand_name'] : "";
  157. $unit = Db::name("unit")->where(["id" => $value['good_unit']])->find();
  158. $value['unit'] = isset($unit['unit']) ? $unit['unit'] : "";
  159. $company = Db::name("business")->where(["companyNo" => $value['companyNo']])->find();
  160. $value['company'] = isset($company['company']) ? $company['company'] : "";
  161. $supplier = Db::name("supplier")->where(['code' => $value['supplierNo']])->find();
  162. $value['supplier_name'] = isset($supplier['name']) ? $supplier['name'] : "";
  163. $value['exclusive'] = makeExcluse($value['is_exclusive']);
  164. $value['noble_name'] = isset($value['noble_metal']) && $value['noble_metal'] != 0 ? $this->noble[$value['noble_metal']] : "";
  165. //如果一个spucode在任意平台上线,那么就视为它上线,即手动把它的is_online值改为1
  166. if (isset($exam_statuss[$value['spuCode']]) || isset($exam_status_yz[$value['spuCode']])) $value['is_online'] = 1;
  167. $value['charger_company_name'] = $item[$value['chargerid']]??'';
  168. $data[] = $value;
  169. }
  170. return json_show(0, "获取成功", ['list' => $data, 'count' => $count]);
  171. }
  172. //创建商品
  173. public function createGood()
  174. {
  175. $this->post = $this->request->filter('trim')->post();
  176. $good_name = isset($this->post['good_name']) && $this->post['good_name'] != "" ? trim($this->post['good_name']) : "";
  177. if ($good_name == "") {
  178. return json_show(1004, "商品名称不能为空");
  179. }
  180. $cat_id = isset($this->post['cat_id']) && $this->post['cat_id'] != "" ? intval($this->post['cat_id']) : "";
  181. if ($cat_id == '') {
  182. return json_show(1004, "商品分类不能为空");
  183. }
  184. //不允许创建贵金属商品
  185. $top_cat_id = made($cat_id);//获取所有分类
  186. $top_cat_id = isset($top_cat_id[0]['id']) ? $top_cat_id[0]['id'] : 0;//获取顶级分类id
  187. if($top_cat_id && $top_cat_id==6) return json_show(1004,'不允许创建贵金属商品');
  188. $brandid = isset($this->post['brandid']) && $this->post['brandid'] != "" ? intval($this->post['brandid']) : "";
  189. if ($brandid == '') {
  190. return json_show(1004, "商品品牌不能为空");
  191. }
  192. $unit = isset($this->post['unit']) && $this->post['unit'] != "" ? trim($this->post['unit']) : "";
  193. if ($unit == '') {
  194. return json_show(1004, "商品单位不能为空");
  195. }
  196. $good_type = isset($this->post['good_type']) && $this->post['good_type'] !== "" ? intval($this->post['good_type']) : "";
  197. if ($good_type === '') {
  198. return json_show(1004, "参数good_type不能为空");
  199. }
  200. $moq = 0;
  201. $customized = 0;
  202. if ($good_type == 1) {
  203. $moq = isset($this->post['moq']) && $this->post['moq'] !== "" ? intval($this->post['moq']) : "";
  204. if ($moq === '') {
  205. return json_show(1004, "定制商品起订量不能为空");
  206. }
  207. $customized = isset($this->post['customized']) && $this->post['customized'] !== "" ? intval($this->post['customized']) : "";
  208. if ($customized === '') {
  209. return json_show(1004, "参数customized不能为空");
  210. }
  211. }
  212. $is_exclusive = isset($this->post['is_exclusive']) && $this->post['is_exclusive'] !== "" ? intval($this->post['is_exclusive']) : "";
  213. if ($is_exclusive === '') {
  214. return json_show(1004, "参数is_exclusive不能为空");
  215. }
  216. $tax = isset($this->post['tax']) && $this->post['tax'] !== "" ? intval($this->post['tax']) : "";
  217. if ($tax === '') {
  218. return json_show(1004, "参数tax不能为空");
  219. }
  220. $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] != "" ? trim($this->post['supplierNo']) : "";
  221. if ($supplierNo == '') {
  222. return json_show(1004, "参数supplierNo不能为空");
  223. }
  224. $good_size = isset($this->post['good_size']) && $this->post['good_size'] != "" ? trim($this->post['good_size']) : "";
  225. if ($good_size == '') {
  226. return json_show(1004, "参数good_size不能为空");
  227. }
  228. $company_id = isset($this->post['company_id']) && $this->post['company_id'] != "" ? trim($this->post['company_id']) : "";
  229. if ($company_id == '') {
  230. return json_show(1004, "参数company_id不能为空");
  231. }
  232. $is_auth = isset($this->post['is_auth']) && $this->post['is_auth'] !== "" ? intval($this->post['is_auth']) : "";
  233. if ($is_auth === '') {
  234. return json_show(1004, "参数is_auth不能为空");
  235. }
  236. $auth_img = isset($this->post['auth_img']) && $this->post['auth_img'] != "" ? trim($this->post['auth_img']) : "";
  237. // if($auth_img==''){
  238. // return json_show(1004,"商品不能为空");
  239. // }
  240. $after_sales = isset($this->post['after_sales']) && $this->post['after_sales'] != "" ? trim($this->post['after_sales']) : "";
  241. if ($after_sales == "") {
  242. return json_show(1004, "参数after_sales不能为空");
  243. }
  244. $craft_desc = isset($this->post['craft_desc']) && $this->post['craft_desc'] != "" ? trim($this->post['craft_desc']) : "";
  245. $good_remark = isset($this->post['good_remark']) && $this->post['good_remark'] != "" ? trim($this->post['good_remark']) : "";
  246. if ($good_remark === "") {
  247. return json_show(1004, "参数good_remark不能为空");
  248. }
  249. $weight = isset($this->post['weight']) && $this->post['weight'] !== "" ? floatval($this->post['weight']) : "";
  250. if ($weight === "") {
  251. return json_show(1004, "参数weight不能为空");
  252. }
  253. $packing_way = isset($this->post['packing_way']) && $this->post['packing_way'] !== "" ? trim($this->post['packing_way']) : "";
  254. if ($packing_way === "") {
  255. return json_show(1004, "参数packing_way不能为空");
  256. }
  257. $packing_size = isset($this->post['packing_size']) && $this->post['packing_size'] !== "" ? trim($this->post['packing_size']) : "";
  258. if ($packing_size === "") {
  259. return json_show(1004, "参数packing_size不能为空");
  260. }
  261. $packing_spec = isset($this->post['packing_spec']) && $this->post['packing_spec'] !== "" ? trim($this->post['packing_spec']) : "";
  262. if ($packing_spec === "") {
  263. return json_show(1004, "参数packing_spec不能为空");
  264. }
  265. $packing_weight = isset($this->post['packing_weight']) && $this->post['packing_weight'] !== "" ? floatval($this->post['packing_weight']) : "";
  266. if ($packing_weight === "") {
  267. return json_show(1004, "参数packing_weight不能为空");
  268. }
  269. $packing_list = isset($this->post['packing_list']) && $this->post['packing_list'] !== "" ? trim($this->post['packing_list']) : "";
  270. if ($packing_list === "") {
  271. return json_show(1004, "参数packing_list不能为空");
  272. }
  273. $good_bar = isset($this->post['good_bar']) && $this->post['good_bar'] !== "" ? trim($this->post['good_bar']) : "";
  274. $supply_area = isset($this->post['supply_area']) && $this->post['supply_area'] !== "" ? intval($this->post['supply_area']) : "";
  275. if ($supply_area === "") {
  276. return json_show(1004, "参数supply_area不能为空");
  277. }
  278. $delivery_place = isset($this->post['delivery_place']) && $this->post['delivery_place'] !== "" ? trim($this->post['delivery_place']) : "";
  279. if ($delivery_place === "") {
  280. return json_show(1004, "参数delivery_place不能为空");
  281. }
  282. $origin_place = isset($this->post['origin_place']) && $this->post['origin_place'] !== "" ? trim($this->post['origin_place']) : "";
  283. if ($origin_place === "") {
  284. return json_show(1004, "参数origin_place不能为空");
  285. }
  286. $delivery_day = isset($this->post['delivery_day']) && $this->post['delivery_day'] !== "" ? intval($this->post['delivery_day']) : "";
  287. if ($delivery_day === "") {
  288. return json_show(1004, "参数delivery_day不能为空");
  289. }
  290. $lead_time = isset($this->post['lead_time']) && $this->post['lead_time'] !== "" ? intval($this->post['lead_time']) : "0";
  291. $cgd_gold_price = isset($this->post['cgd_gold_price']) && $this->post['cgd_gold_price'] !== "" ? floatval($this->post['cgd_gold_price']) : "0";
  292. // if($lead_time===""){
  293. // return json_show(1004,"参数lead_time不能为空");
  294. // }
  295. $sample_day = isset($this->post['sample_day']) && $this->post['sample_day'] !== "" ? intval($this->post['sample_day']) : "0";
  296. // if($sample_day===""){
  297. // return json_show(1004,"参数sample_day不能为空");
  298. // }
  299. $sample_fee = isset($this->post['sample_fee']) && $this->post['sample_fee'] !== "" ? floatval($this->post['sample_fee']) : "0";
  300. $is_stock = isset($this->post['is_stock']) && $this->post['is_stock'] !== "" ? intval($this->post['is_stock']) : "";
  301. if ($is_stock === "") {
  302. return json_show(1004, "参数is_stock不能为空");
  303. }
  304. // $stock_moq=0 ;//库存品备库起订量; 如果是0 表示无限制;
  305. $stock_moq = isset($this->post['stock_moq']) && $this->post['stock_moq'] !== "" ? intval($this->post['stock_moq']) : "0";
  306. if ($is_stock == 1 && $stock_moq == 0) {
  307. return json_show(1004, "库存品备库起订量不能为零");
  308. }
  309. $is_diff = isset($this->post['is_diff']) && $this->post['is_diff'] !== "" ? intval($this->post['is_diff']) : "0";
  310. $good_img = isset($this->post['good_img']) && $this->post['good_img'] != "" ? trim($this->post['good_img']) : "";
  311. $config = isset($this->post['config']) && $this->post['config'] !== "" ? trim($this->post['config']) : "";
  312. $other_config = isset($this->post['other_config']) && $this->post['other_config'] !== "" ? trim($this->post['other_config']) : "";
  313. if ($good_img === "") {
  314. return json_show(1004, "参数good_img不能为空");
  315. }
  316. $good_thumb_img = isset($this->post['good_thumb_img']) && $this->post['good_thumb_img'] !== "" ? trim($this->post['good_thumb_img']) : "";
  317. if ($good_thumb_img === "") {
  318. return json_show(1004, "参数good_thumb_img不能为空");
  319. }
  320. $good_info_img = isset($this->post['good_info_img']) && $this->post['good_info_img'] != "" ? trim($this->post['good_info_img']) : "";
  321. if ($good_info_img === "") {
  322. return json_show(1004, "参数good_info_img不能为空");
  323. }
  324. $cert_fee = isset($this->post['cert_fee']) && $this->post['cert_fee'] !== "" ? floatval($this->post['cert_fee']) : "0";
  325. $packing_fee = isset($this->post['packing_fee']) && $this->post['packing_fee'] !== "" ? floatval($this->post['packing_fee']) : "0";
  326. $cost_fee = isset($this->post['cost_fee']) && $this->post['cost_fee'] !== "" ? floatval($this->post['cost_fee']) : "0";
  327. $mark_fee = isset($this->post['mark_fee']) && $this->post['mark_fee'] !== "" ? floatval($this->post['mark_fee']) : "0";
  328. $demo_fee = isset($this->post['demo_fee']) && $this->post['demo_fee'] !== "" ? floatval($this->post['demo_fee']) : "0";
  329. $open_fee = isset($this->post['open_fee']) && $this->post['open_fee'] !== "" ? floatval($this->post['open_fee']) : "0";
  330. $noble_metal = isset($this->post['noble_metal']) && $this->post['noble_metal'] !== "" ? intval($this->post['noble_metal']) : "0";
  331. $noble_weight = isset($this->post['noble_weight']) && $this->post['noble_weight'] !== "" ? floatval($this->post['noble_weight']) : "0";
  332. $is_gold_price = isset($this->post['is_gold_price']) && $this->post['is_gold_price'] !== "" ? intval($this->post['is_gold_price']) : "0";
  333. $market_price = isset($this->post['market_price']) && $this->post['market_price'] !== "" ? floatval($this->post['market_price']) : "";
  334. if ($market_price === "") {
  335. return json_show(1004, "参数market_price不能为空");
  336. }
  337. $nake_price = isset($this->post['nake_price']) && $this->post['nake_price'] !== "" ? floatval($this->post['nake_price']) : "0";
  338. // $is_step = isset($this->post['is_step'])&&$this->post['is_step']!==""? intval($this->post['is_step']):"";
  339. // if($is_step===""){
  340. // return json_show(1004,"参数is_step不能为空");
  341. // }
  342. $speclist = isset($this->post['speclist']) && !empty($this->post['speclist']) ? $this->post['speclist'] : "";
  343. $good_ladder = isset($this->post['good_ladder']) && !empty($this->post['good_ladder']) ? $this->post['good_ladder'] : "";
  344. // if($is_step==1 && $good_ladder==""){
  345. // return json_show(1004,"启用阶梯,阶梯价不能为空");
  346. // }
  347. $is_support_barter = isset($this->post['is_support_barter']) && $this->post['is_support_barter'] !== "" ? intval($this->post['is_support_barter']) : 1;
  348. // $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  349. // if($token==''){
  350. // return json_show(105,"参数token不能为空");
  351. // }
  352. // $user =GetUserInfo($token);
  353. // if(empty($user)||$user['code']!=0){
  354. // return json_show(1002,"创建人数据不存在");
  355. // }
  356. $createrid = $this->request->user['uid']; //isset($user["data"]['id']) ? $user["data"]['id'] : "";
  357. $creater = $this->request->user['nickname'];//isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  358. $spucode = makeNo("SKU");
  359. Db::startTrans();
  360. try {
  361. $charger = Db::name('supplier')
  362. ->where(['code' => $this->request->user['supplierNo'], 'is_del' => 0])
  363. ->field('id,person,personid')
  364. ->findOrEmpty();
  365. $data = [
  366. "spuCode" => $spucode,
  367. "good_code" => '',
  368. "good_name" => $good_name,
  369. "cat_id" => $cat_id,
  370. 'brand_id' => $brandid,
  371. "good_unit" => $unit,
  372. "good_type" => $good_type,
  373. "moq" => $moq,
  374. "is_exclusive" => $is_exclusive,
  375. "customized" => $customized,
  376. "companyNo" => $company_id,
  377. "tax" => $tax,
  378. "supplierNo" => $supplierNo,
  379. "good_size" => $good_size,
  380. "is_auth" => $is_auth,
  381. "is_stock" => $is_stock,
  382. "auth_img" => $auth_img,
  383. "after_sales" => $after_sales,
  384. "craft_desc" => $craft_desc,
  385. "good_remark" => $good_remark,
  386. "weight" => $weight,
  387. "packing_way" => $packing_way,
  388. "packing_size" => $packing_size,
  389. "packing_spec" => $packing_spec,
  390. "packing_list" => $packing_list,
  391. "packing_weight" => $packing_weight,
  392. "good_bar" => $good_bar,
  393. "supply_area" => $supply_area,
  394. "delivery_place" => $delivery_place,
  395. "origin_place" => $origin_place,
  396. "delivery_day" => $delivery_day,
  397. "lead_time" => $lead_time,
  398. "sample_day" => $sample_day,
  399. "sample_fee" => $sample_fee,
  400. "good_img" => $good_img,
  401. "good_thumb_img" => $good_thumb_img,
  402. "good_info_img" => $good_info_img,
  403. "cert_fee" => $cert_fee,
  404. "packing_fee" => $packing_fee,
  405. "cost_fee" => $cost_fee,
  406. "mark_fee" => $mark_fee,
  407. "demo_fee" => $demo_fee,
  408. "open_fee" => $open_fee,
  409. "noble_metal" => $noble_metal,
  410. "cgd_gold_price" => $cgd_gold_price,
  411. "noble_weight" => $noble_weight,
  412. "is_gold_price" => $is_gold_price,
  413. "market_price" => $market_price,
  414. "nake_price" => $nake_price,
  415. "is_diff" => $is_diff,
  416. "config" => $config,
  417. "other_config" => $other_config,
  418. "field_change" => '',
  419. "is_step" => count($good_ladder) > 1 ? 1 : 0,//如果阶梯价个数大于1,说明启用阶梯价
  420. "is_online" => 0,
  421. "stock_moq" => $stock_moq,
  422. "status" => 0,
  423. "createrid" => $createrid,
  424. "creater" => $creater,
  425. "addtime" => date("Y-m-d H:i:s"),
  426. "updatetime" => date("Y-m-d H:i:s"),
  427. 'is_support_barter' => $is_support_barter,
  428. 'chargerid' => $charger['personid'] ?? 0,
  429. 'charger' => $charger['person'] ?? '',//负责人,取所属供应商的创建人
  430. ];
  431. $in = Db::name("good_basic")->insertGetId($data);
  432. if ($in) {
  433. if ($speclist !== "" && !empty($speclist)) {
  434. $temp = [];
  435. foreach ($speclist as $value) {
  436. $lemp = [];
  437. $lemp['spuCode'] = $spucode;
  438. $lemp['spec_id'] = $value['spec_id'];
  439. $lemp['spec_value_id'] = $value['spec_value_id'];
  440. $lemp['addtime'] = date("Y-m-d H:i:s");
  441. $lemp['updatetime'] = date("Y-m-d H:i:s");
  442. $temp[] = $lemp;
  443. }
  444. $count = Db::name("good_spec")->insertAll($temp);
  445. if ($count == 0) {
  446. Db::rollback();
  447. return json_show(1004, "商品规格值创建失败");
  448. }
  449. }
  450. // $catinfo = Db::name("cat")->where(["id" => $cat_id])->find();
  451. // $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate'] / 100 : 0;
  452. if ($good_ladder !== "" && !empty($good_ladder)) {
  453. $temp = [];
  454. foreach ($good_ladder as $value) {
  455. $lemp = [];
  456. $lemp['spuCode'] = $spucode;
  457. $lemp['min_num'] = $value['min_num'];
  458. $lemp['nake_fee'] = $value['nake_fee'];
  459. $lemp['cost_fee'] = $value['cost_fee'];
  460. $lemp['delivery_fee'] = $value['delivery_fee'];
  461. $lemp['cert_fee'] = $value['cert_fee'];
  462. $lemp['mark_fee'] = $value['mark_fee'];
  463. $lemp['package_fee'] = $value['package_fee'];
  464. $lemp['other_fee'] = $value['other_fee'];
  465. if ($is_gold_price == 1 && $top_cat_id == 6) {
  466. //$is_gold_price==1 表示启用实时金价,cat_id==6表示贵金属
  467. $gold = Db::name("gold_price1")->where(["type" => $noble_metal, "status" => 1, "is_del" => 0])->order("addtime desc")->find();
  468. //$lemp['nake_total'] = $noble_weight * $gold['price'] + $value['cost_fee'] * $noble_weight + $value['mark_fee'] + $value['package_fee'] + $value['cert_fee'] + $value['nake_fee'] + $value['delivery_fee'] + $value['other_fee'];
  469. //成本合计=贵金属重量*供应商采购金价 + 工艺费*贵金属重量+加标费+包装费+证书费+成本裸价+运费+其他费用
  470. //成本总计启用实时金价时,采用供应商实时金价
  471. $lemp['nake_total'] = $noble_weight * $gold['price'] + $value['cost_fee'] * $noble_weight +
  472. $value['mark_fee'] + $value['package_fee'] + $value['cert_fee'] + $value['nake_fee'] + $value['delivery_fee'] + $value['other_fee'];
  473. } else {
  474. $lemp['nake_total'] = $value['nake_fee'] + $value['delivery_fee'] + $value['cert_fee'] + $value['mark_fee'] + $value['package_fee'] + $value['other_fee'];
  475. }
  476. $lemp['creater_id'] = $createrid;
  477. $lemp['creater'] = $creater;
  478. $lemp['is_del'] = 0;
  479. $lemp['addtime'] = date("Y-m-d H:i:s");
  480. $lemp['updatetime'] = date("Y-m-d H:i:s");
  481. $temp[] = $lemp;
  482. }
  483. $count = Db::name("good_nake")->insertAll($temp);
  484. if ($count == 0) {
  485. Db::rollback();
  486. return json_show(1004, "商品规格值创建失败");
  487. }
  488. }
  489. //修改状态,添加待办
  490. ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
  491. "order_code" => $spucode,//咨询单详情编号
  492. "status" => 0,//这里的status是之前的值
  493. "action_remark" => '',//备注
  494. "action_type" => "create"//新建create,编辑edit,更改状态status
  495. ], "SPCB", 0, $data);
  496. ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
  497. "order_type" => 'SPCB',
  498. "order_code" => $spucode,//咨询单详情编号
  499. "order_id" => $in,
  500. "order_status" => 0,
  501. "before_status" => 0,
  502. 'holder_id' => $data['createrid'],
  503. 'person_id' => Db::name('supplier')->where(['code' => $this->request->user['supplierNo'], 'is_del' => 0])->value('personid'),
  504. ]);
  505. Db::commit();
  506. return json_show(0, "创建成功", ["spuCode" => $spucode]);
  507. } else {
  508. Db::rollback();
  509. return json_show(1004, "商品创建失败");
  510. }
  511. } catch (\Exception $e) {
  512. Db::rollback();
  513. return json_show(1004, $e->getMessage());
  514. }
  515. }
  516. //修改商品基础信息
  517. public function updateGoodBasicsInfo()
  518. {
  519. $this->post = $this->request->filter('trim')->post();
  520. $supcode = isset($this->post['spuCode']) && $this->post['spuCode'] != "" ? trim($this->post['spuCode']) : "";
  521. if ($supcode == "") {
  522. return json_show(1004, "参数spuCode不能为空");
  523. }
  524. $data = Db::name("good_basic")->where(["spuCode" => $supcode, "is_del" => 0])->find();
  525. if ($data == false) {
  526. return json_show(1004, "未找到商品数据");
  527. }
  528. $is_down = Db::name("good_platform")->where(["spuCode" => $supcode, "is_del" => 0])->where("exam_status", "<>", 5)->find();
  529. if ($is_down != false) {
  530. return json_show(1004, "存在未下线商品数据");
  531. }
  532. if ($data['status'] != 1) return json_show(1005, '该状态下不允许修改基础信息');
  533. $good_name = isset($this->post['good_name']) && $this->post['good_name'] != "" ? trim($this->post['good_name']) : "";
  534. if ($good_name == "") {
  535. return json_show(1004, "商品名称不能为空");
  536. }
  537. $cat_id = isset($this->post['cat_id']) && $this->post['cat_id'] != "" ? intval($this->post['cat_id']) : "";
  538. if ($cat_id == '') {
  539. return json_show(1004, "商品分类不能为空");
  540. }
  541. $brandid = isset($this->post['brandid']) && $this->post['brandid'] != "" ? intval($this->post['brandid']) : "0";
  542. // if($brandid==''){
  543. // return json_show(1004,"商品品牌不能为空");
  544. // }
  545. $unit = isset($this->post['unit']) && $this->post['unit'] != "" ? trim($this->post['unit']) : "";
  546. if ($unit == '') {
  547. return json_show(1004, "商品单位不能为空");
  548. }
  549. $good_type = isset($this->post['good_type']) && $this->post['good_type'] !== "" ? intval($this->post['good_type']) : "";
  550. if ($good_type === '') {
  551. return json_show(1004, "参数good_type不能为空");
  552. }
  553. $moq = 0;
  554. $customized = 0;
  555. if ($good_type == 1) {
  556. $moq = isset($this->post['moq']) && $this->post['moq'] !== "" ? intval($this->post['moq']) : "";
  557. if ($moq === '') {
  558. return json_show(1004, "定制商品起订量不能为空");
  559. }
  560. $customized = isset($this->post['customized']) && $this->post['customized'] !== "" ? intval($this->post['customized']) : "";
  561. if ($customized === '') {
  562. return json_show(1004, "参数customized不能为空");
  563. }
  564. }
  565. $is_exclusive = isset($this->post['is_exclusive']) && $this->post['is_exclusive'] !== "" ? intval($this->post['is_exclusive']) : "";
  566. if ($is_exclusive === '') {
  567. return json_show(1004, "参数is_exclusive不能为空");
  568. }
  569. // $customized = isset($this->post['customized'])&&$this->post['customized']!==""? intval($this->post['customized']):"";
  570. // if($customized===''){
  571. // return json_show(1004,"参数customized不能为空");
  572. // }
  573. $tax = isset($this->post['tax']) && $this->post['tax'] !== "" ? intval($this->post['tax']) : "";
  574. if ($tax === '') {
  575. return json_show(1004, "参数tax不能为空");
  576. }
  577. $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] != "" ? trim($this->post['supplierNo']) : "";
  578. if ($supplierNo == '') {
  579. return json_show(1004, "参数supplierNo不能为空");
  580. }
  581. $good_size = isset($this->post['good_size']) && $this->post['good_size'] != "" ? trim($this->post['good_size']) : "";
  582. if ($good_size == '') {
  583. return json_show(1004, "参数good_size不能为空");
  584. }
  585. $company_id = isset($this->post['company_id']) && $this->post['company_id'] != "" ? trim($this->post['company_id']) : "";
  586. if ($company_id == '') {
  587. return json_show(1004, "参数company_id不能为空");
  588. }
  589. $is_auth = isset($this->post['is_auth']) && $this->post['is_auth'] !== "" ? intval($this->post['is_auth']) : "";
  590. if ($is_auth === '') {
  591. return json_show(1004, "参数is_auth不能为空");
  592. }
  593. $auth_img = isset($this->post['auth_img']) && $this->post['auth_img'] != "" ? trim($this->post['auth_img']) : "";
  594. // if($auth_img==''){
  595. // return json_show(1004,"商品不能为空");
  596. // }
  597. $after_sales = isset($this->post['after_sales']) && $this->post['after_sales'] != "" ? trim($this->post['after_sales']) : "";
  598. if ($after_sales == "") {
  599. return json_show(1004, "参数after_sales不能为空");
  600. }
  601. $craft_desc = isset($this->post['craft_desc']) && $this->post['craft_desc'] != "" ? trim($this->post['craft_desc']) : "";
  602. $good_remark = isset($this->post['good_remark']) && $this->post['good_remark'] != "" ? trim($this->post['good_remark']) : "";
  603. if ($good_remark === "") {
  604. return json_show(1004, "参数good_remark不能为空");
  605. }
  606. $weight = isset($this->post['weight']) && $this->post['weight'] !== "" ? floatval($this->post['weight']) : "";
  607. if ($weight === "") {
  608. return json_show(1004, "参数weight不能为空");
  609. }
  610. $packing_way = isset($this->post['packing_way']) && $this->post['packing_way'] !== "" ? trim($this->post['packing_way']) : "";
  611. if ($packing_way === "") {
  612. return json_show(1004, "参数packing_way不能为空");
  613. }
  614. $packing_size = isset($this->post['packing_size']) && $this->post['packing_size'] !== "" ? trim($this->post['packing_size']) : "";
  615. if ($packing_size === "") {
  616. return json_show(1004, "参数packing_size不能为空");
  617. }
  618. $packing_spec = isset($this->post['packing_spec']) && $this->post['packing_spec'] !== "" ? trim($this->post['packing_spec']) : "";
  619. if ($packing_spec === "") {
  620. return json_show(1004, "参数packing_spec不能为空");
  621. }
  622. $packing_weight = isset($this->post['packing_weight']) && $this->post['packing_weight'] !== "" ? floatval($this->post['packing_weight']) : "";
  623. if ($packing_weight === "") {
  624. return json_show(1004, "参数packing_weight不能为空");
  625. }
  626. $packing_list = isset($this->post['packing_list']) && $this->post['packing_list'] !== "" ? trim($this->post['packing_list']) : "";
  627. if ($packing_list === "") {
  628. return json_show(1004, "参数packing_list不能为空");
  629. }
  630. $good_bar = isset($this->post['good_bar']) && $this->post['good_bar'] !== "" ? trim($this->post['good_bar']) : "";
  631. $supply_area = isset($this->post['supply_area']) && $this->post['supply_area'] !== "" ? intval($this->post['supply_area']) : "";
  632. if ($supply_area === "") {
  633. return json_show(1004, "参数supply_area不能为空");
  634. }
  635. $delivery_place = isset($this->post['delivery_place']) && $this->post['delivery_place'] !== "" ? $this->post['delivery_place'] : "";
  636. if ($delivery_place === "") {
  637. return json_show(1004, "参数delivery_place不能为空");
  638. }
  639. $origin_place = isset($this->post['origin_place']) && $this->post['origin_place'] !== "" ? $this->post['origin_place'] : "";
  640. if ($origin_place === "") {
  641. return json_show(1004, "参数origin_place不能为空");
  642. }
  643. $delivery_day = isset($this->post['delivery_day']) && $this->post['delivery_day'] !== "" ? intval($this->post['delivery_day']) : "";
  644. if ($delivery_day === "") {
  645. return json_show(1004, "参数delivery_day不能为空");
  646. }
  647. $lead_time = isset($this->post['lead_time']) && $this->post['lead_time'] !== "" ? intval($this->post['lead_time']) : "0";
  648. // if($lead_time===""){
  649. // return json_show(1004,"参数lead_time不能为空");
  650. // }
  651. $sample_day = isset($this->post['sample_day']) && $this->post['sample_day'] !== "" ? intval($this->post['sample_day']) : "0";
  652. // if($sample_day===""){
  653. // return json_show(1004,"参数sample_day不能为空");
  654. // }
  655. // $sample_fee = isset($this->post['sample_fee'])&&$this->post['sample_fee']!==""? floatval
  656. //($this->post['sample_fee']):"0";
  657. $config = isset($this->post['config']) && $this->post['config'] !== "" ? trim($this->post['config']) : "";
  658. $other_config = isset($this->post['other_config']) && $this->post['other_config'] !== "" ? trim($this->post['other_config']) : "";
  659. $is_diff = isset($this->post['is_diff']) && $this->post['is_diff'] !== "" ? intval($this->post['is_diff']) : "0";
  660. $is_stock = isset($this->post['is_stock']) && $this->post['is_stock'] !== "" ? intval($this->post['is_stock']) : "0";
  661. $stock_moq = isset($this->post['stock_moq']) && $this->post['stock_moq'] !== "" ? intval($this->post['stock_moq']) : "0";
  662. if ($is_stock == 1 && $stock_moq == 0) {
  663. return json_show(1004, "库存品备库起订量不能为零");
  664. }
  665. $good_img = isset($this->post['good_img']) && $this->post['good_img'] != "" ? trim($this->post['good_img']) : "";
  666. if ($good_img === "") {
  667. return json_show(1004, "参数good_img不能为空");
  668. }
  669. $good_thumb_img = isset($this->post['good_thumb_img']) && $this->post['good_thumb_img'] !== "" ? trim($this->post['good_thumb_img']) : "";
  670. if ($good_thumb_img === "") {
  671. return json_show(1004, "参数good_thumb_img不能为空");
  672. }
  673. $good_info_img = isset($this->post['good_info_img']) && !empty($this->post['good_info_img']) ? trim($this->post['good_info_img']) : "";
  674. if ($good_info_img === "") {
  675. return json_show(1004, "参数good_info_img不能为空");
  676. }
  677. $count = Db::name("good_nake")->where(["spuCode" => $supcode, "is_del" => 0])->count();
  678. $speclist = isset($this->post['speclist']) && !empty($this->post['speclist']) ? $this->post['speclist'] : "";
  679. $uid = $this->request->user['uid'];
  680. $nickname = $this->request->user['nickname'];
  681. Db::startTrans();
  682. try {
  683. $temp = [
  684. "good_name" => $good_name,
  685. "cat_id" => $cat_id,
  686. 'brand_id' => $brandid,
  687. "good_unit" => $unit,
  688. "good_type" => $good_type,
  689. "companyNo" => $company_id,
  690. "moq" => $moq,
  691. "is_exclusive" => $is_exclusive,
  692. "customized" => $customized,
  693. "tax" => $tax,
  694. "supplierNo" => $supplierNo,
  695. "is_auth" => $is_auth,
  696. "good_size" => $good_size,
  697. "auth_img" => $auth_img,
  698. "after_sales" => $after_sales,
  699. "craft_desc" => $craft_desc,
  700. "good_remark" => $good_remark,
  701. "weight" => $weight,
  702. "packing_way" => $packing_way,
  703. "packing_size" => $packing_size,
  704. "packing_spec" => $packing_spec,
  705. "packing_list" => $packing_list,
  706. "packing_weight" => $packing_weight,
  707. "good_bar" => $good_bar,
  708. "supply_area" => $supply_area,
  709. "delivery_place" => $delivery_place,
  710. "origin_place" => $origin_place,
  711. "delivery_day" => $delivery_day,
  712. "lead_time" => $lead_time,
  713. "sample_day" => $sample_day,
  714. "is_diff" => $is_diff,
  715. 'is_stock' => $is_stock,
  716. "config" => $config,
  717. "other_config" => $other_config,
  718. "good_img" => $good_img,
  719. "stock_moq" => $stock_moq,
  720. "good_thumb_img" => $good_thumb_img,
  721. "good_info_img" => $good_info_img,
  722. "status" => $count > 0 ? 2 : 1,
  723. "updatetime" => date("Y-m-d H:i:s")
  724. ];
  725. $field = array_diff_assoc($temp, $data);
  726. $temp['field_change'] = empty($field) ? "" : json_encode(array_keys($field));
  727. $up = Db::name("good_basic")->where(["spuCode" => $supcode, "is_del" => 0])->save($temp);
  728. $timp = array_diff($temp, $data);
  729. $json = json_encode($timp, JSON_UNESCAPED_UNICODE);
  730. $jsp = json_encode($data, JSON_UNESCAPED_UNICODE);
  731. if ($up) {
  732. ChangeLog::logAdd(3, $data['spuCode'], $jsp, $json, ['id' => $uid, 'nickname' => $nickname], $this->post);
  733. if ($speclist !== "" && !empty($speclist)) {
  734. foreach ($speclist as $value) {
  735. $lemp = [];
  736. isset($value["id"]) && $value["id"] != '' ? $lemp['id'] = $value['id'] : "";
  737. $lemp['spuCode'] = $supcode;
  738. $lemp['spec_id'] = $value['spec_id'];
  739. $lemp['spec_value_id'] = $value['spec_value_id'];
  740. $lemp['is_del'] = isset($value['is_del']) ? $value['is_del'] : 0;
  741. isset($value["id"]) && $value["id"] != '' ? "" : $lemp['addtime'] = date("Y-m-d H:i:s");
  742. $lemp['updatetime'] = date("Y-m-d H:i:s");
  743. $count = Db::name("good_spec")->save($lemp);
  744. if ($count == false) {
  745. Db::rollback();
  746. return json_show(1004, "商品规格值修改失败");
  747. }
  748. }
  749. }
  750. //修改状态,添加待办
  751. ActionLog::logAdd(['id' => $uid, 'nickname' => $nickname], [
  752. "order_code" => $supcode,//咨询单详情编号
  753. "status" => $data['status'],//这里的status是之前的值
  754. "action_remark" => '',//备注
  755. "action_type" => "edit"//新建create,编辑edit,更改状态status
  756. ], "SPCB", $temp['status'], $data);
  757. ProcessOrder::AddProcess(['id' => $uid, 'nickname' => $nickname], [
  758. "order_type" => 'SPCB',
  759. "order_code" => $supcode,//咨询单详情编号
  760. "order_id" => $data['id'],
  761. "order_status" => $temp['status'],
  762. "before_status" => $data['status'],
  763. 'holder_id' => $data['createrid'],
  764. 'person_id' => Db::name('supplier')->where(['code' => $this->request->user['supplierNo'], 'is_del' => 0])->value('personid'),
  765. ]);
  766. Db::commit();
  767. return json_show(0, "更新成功");
  768. } else {
  769. Db::rollback();
  770. return json_show(1005, "更新失败");
  771. }
  772. } catch (\Exception $e) {
  773. Db::rollback();
  774. return json_show(1004, $e->getMessage());
  775. }
  776. }
  777. //修改商品价格信息
  778. public function updateGoodPriceInfo()
  779. {
  780. $this->post = $this->request->filter('trim')->post();
  781. $supcode = isset($this->post['spuCode']) && $this->post['spuCode'] != "" ? trim($this->post['spuCode']) : "";
  782. if ($supcode == "") {
  783. return json_show(1004, "参数spuCode不能为空");
  784. }
  785. $datas = Db::name("good_basic")->where(["spuCode" => $supcode, "is_del" => 0])->find();
  786. if ($datas == false) {
  787. return json_show(1004, "未找到商品数据");
  788. }
  789. if ($datas['status'] != 1) return json_show(1005, '该状态下不允许修改价格信息');
  790. $is_down = Db::name("good_platform")
  791. ->where(["spuCode" => $supcode, "is_del" => 0])
  792. ->where("exam_status", "<>", 5)
  793. ->find();
  794. if ($is_down != false) {
  795. return json_show(1004, "存在未下线商品数据");
  796. }
  797. $cert_fee = isset($this->post['cert_fee']) && $this->post['cert_fee'] !== "" ? floatval($this->post['cert_fee']) : "0";
  798. $packing_fee = isset($this->post['packing_fee']) && $this->post['packing_fee'] !== "" ? floatval($this->post['packing_fee']) : "0";
  799. $cost_fee = isset($this->post['cost_fee']) && $this->post['cost_fee'] !== "" ? floatval($this->post['cost_fee']) : "0";
  800. $mark_fee = isset($this->post['mark_fee']) && $this->post['mark_fee'] !== "" ? floatval($this->post['mark_fee']) : "0";
  801. $demo_fee = isset($this->post['demo_fee']) && $this->post['demo_fee'] !== "" ? floatval($this->post['demo_fee']) : "0";
  802. $open_fee = isset($this->post['open_fee']) && $this->post['open_fee'] !== "" ? floatval($this->post['open_fee']) : "0";
  803. $sample_fee = isset($this->post['sample_fee']) && $this->post['sample_fee'] !== "" ? floatval($this->post['sample_fee']) : "0";
  804. $noble_metal = isset($this->post['noble_metal']) && $this->post['noble_metal'] !== "" ? intval($this->post['noble_metal']) : "0";
  805. $noble_weight = isset($this->post['noble_weight']) && $this->post['noble_weight'] !== "" ? floatval($this->post['noble_weight']) : "0";
  806. $is_gold_price = isset($this->post['is_gold_price']) && $this->post['is_gold_price'] !== "" ? intval($this->post['is_gold_price']) : "0";
  807. $market_price = isset($this->post['market_price']) && $this->post['market_price'] !== "" ? floatval($this->post['market_price']) : "";
  808. $cgd_gold_price = isset($this->post['cgd_gold_price']) && $this->post['cgd_gold_price'] !== "" ? floatval($this->post['cgd_gold_price']) : "0";
  809. if ($market_price === "") {
  810. return json_show(1004, "参数market_price不能为空");
  811. }
  812. $nake_price = isset($this->post['nake_price']) && $this->post['nake_price'] !== "" ? floatval($this->post['nake_price']) : "";
  813. // $is_step = isset($this->post['is_step'])&&$this->post['is_step']!==""? intval($this->post['is_step']):"";
  814. // if($is_step===""){
  815. // return json_show(1004,"参数is_step不能为空");
  816. // }
  817. $good_ladder = isset($this->post['good_ladder']) && !empty($this->post['good_ladder']) ? $this->post['good_ladder'] : "";
  818. // if($is_step==1 && $good_ladder==""){
  819. // return json_show(1004,"启用阶梯,阶梯价不能为空");
  820. // }
  821. $data = [
  822. "cert_fee" => $cert_fee,
  823. "packing_fee" => $packing_fee,
  824. "cost_fee" => $cost_fee,
  825. "mark_fee" => $mark_fee,
  826. "demo_fee" => $demo_fee,
  827. "open_fee" => $open_fee,
  828. "sample_fee" => $sample_fee,
  829. "noble_metal" => $noble_metal,
  830. "noble_weight" => $noble_weight,
  831. "is_gold_price" => $is_gold_price,
  832. "market_price" => $market_price,
  833. "nake_price" => $nake_price,
  834. "cgd_gold_price" => $cgd_gold_price,
  835. "is_step" => count($good_ladder) > 1 ? 1 : 0,
  836. "status" => "3",
  837. "updatetime" => date("Y-m-d H:i:s")
  838. ];
  839. $field = array_diff_assoc($data, $datas);
  840. $data['field_change'] = empty($field) ? "" : json_encode(array_keys($field));
  841. $uid = $this->request->user['uid'];
  842. $nickname = $this->request->user['nickname'];
  843. Db::startTrans();
  844. try {
  845. $up = Db::name("good_basic")->where(["spuCode" => $supcode, "is_del" => 0])->save($data);
  846. $temp = array_diff($data, $datas);
  847. $json = json_encode($temp, JSON_UNESCAPED_UNICODE);
  848. $jsp = json_encode($datas, JSON_UNESCAPED_UNICODE);
  849. if ($up) {
  850. ChangeLog::logAdd(3, $datas['spuCode'], $jsp, $json, ['id' => $uid, 'nickname' => $nickname], $this->post);
  851. //修改状态,添加待办
  852. ActionLog::logAdd(['id' => $uid, 'nickname' => $nickname], [
  853. "order_code" => $supcode,//咨询单详情编号
  854. "status" => $datas['status'],//这里的status是之前的值
  855. "action_remark" => '',//备注
  856. "action_type" => "edit"//新建create,编辑edit,更改状态status
  857. ], "SPCB", $data['status'], $data);
  858. ProcessOrder::AddProcess(['id' => $uid, 'nickname' => $nickname], [
  859. "order_type" => 'SPCB',
  860. "order_code" => $supcode,//咨询单详情编号
  861. "order_id" => $datas['id'],
  862. "order_status" => $data['status'],
  863. "before_status" => $datas['status'],
  864. 'holder_id' => $datas['createrid'],
  865. 'person_id' => Db::name('supplier')->where(['code' => $this->request->user['supplierNo'], 'is_del' => 0])->value('personid'),
  866. ]);
  867. // $online = Db::name("good_platform")->where(["spuCode"=>$supcode,"is_del"=>0])->find();
  868. // if($online){
  869. // $onup = Db::name("good_platform")->where(["spuCode"=>$supcode,"is_del"=>0])->save
  870. // (["exam_status"=>2,"updatetime"=>date("Y-m-d H:i:s")]);
  871. // if($onup==false){
  872. // Db::rollback();
  873. // return json_show(1004,"商品规成本修改失败");
  874. // }
  875. // //修改状态,添加待办
  876. // ActionLog::logAdd(['id'=>$uid,'nickname'=>$nickname], [
  877. // "order_code" =>$online['skuCode'],//咨询单详情编号
  878. // "status" => $online['exam_status'],//这里的status是之前的值
  879. // "action_remark" => '',//备注
  880. // "action_type" => "edit"//新建create,编辑edit,更改状态status
  881. // ], "SPSX",2,["exam_status"=>2,"updatetime"=>date("Y-m-d H:i:s")]);
  882. //
  883. // ProcessOrder::AddProcess(['id'=>$uid,'nickname'=>$nickname], [
  884. // "order_type" => 'SPSX',
  885. // "order_code" => $online['skuCode'],//咨询单详情编号
  886. // "order_id" => $online['id'],
  887. // "order_status" =>2,"before_status"=>$online['exam_status']
  888. // ]);
  889. // }
  890. if ($good_ladder !== "" && !empty($good_ladder)) {
  891. // $user =GetUserInfo($this->post['token']);
  892. foreach ($good_ladder as $value) {
  893. $lemp = [];
  894. isset($value["id"]) && $value["id"] != '' ? $lemp['id'] = $value['id'] : "";
  895. $lemp['spuCode'] = $supcode;
  896. $lemp['min_num'] = $value['min_num'];
  897. $lemp['nake_fee'] = $value['nake_fee'];
  898. $lemp['cost_fee'] = $value['cost_fee'];
  899. $lemp['delivery_fee'] = $value['delivery_fee'];
  900. $lemp['cert_fee'] = $value['cert_fee'];
  901. $lemp['mark_fee'] = $value['mark_fee'];
  902. $lemp['package_fee'] = $value['package_fee'];
  903. $lemp['other_fee'] = $value['other_fee'];
  904. $top_cat_id = made($datas['cat_id']);//获取所有分类
  905. $top_cat_id = isset($top_cat_id[0]['id']) ? $top_cat_id[0]['id'] : 0;//获取顶级分类id
  906. if ($is_gold_price == 1 && $top_cat_id == 6) {
  907. //$gold =Db::name("gold_price1")->where(["type"=>$noble_metal,"status"=>1,"is_del"=>0])
  908. // ->order("addtime desc")->find();
  909. //$lemp['nake_total'] =$noble_weight*$gold['price'] + $value['cost_fee']*$noble_weight+$value['mark_fee']+$value['package_fee']+$value['cert_fee']+$value['nake_fee']+$value['delivery_fee']+$value['other_fee'];
  910. //成本合计=贵金属重量*供应商采购金价 + 工艺费*贵金属重量+加标费+包装费+证书费+成本裸价+运费+其他费用
  911. //成本总计启用实时金价时,采用供应商实时金价
  912. $lemp['nake_total'] = $noble_weight * $cgd_gold_price + $value['cost_fee'] * $noble_weight +
  913. $value['mark_fee'] + $value['package_fee'] + $value['cert_fee'] + $value['nake_fee'] + $value['delivery_fee'] + $value['other_fee'];
  914. } else {
  915. $lemp['nake_total'] = $value['nake_fee'] + $value['delivery_fee'] + $value['cert_fee'] + $value['mark_fee'] + $value['package_fee'] + $value['other_fee'];
  916. }
  917. $lemp['is_del'] = isset($value['is_del']) ? $value['is_del'] : 0;
  918. $lemp['creater_id'] = $uid;
  919. $lemp['creater'] = $nickname;
  920. isset($value["id"]) && $value["id"] != '' ? "" : $lemp['addtime'] = date("Y-m-d H:i:s");
  921. $lemp['updatetime'] = date("Y-m-d H:i:s");
  922. $count = Db::name("good_nake")->save($lemp);
  923. if ($count == false) {
  924. Db::rollback();
  925. return json_show(1004, "商品规成本修改失败");
  926. }
  927. }
  928. }
  929. Db::commit();
  930. return json_show(0, "更新成功");
  931. } else {
  932. Db::rollback();
  933. return json_show(1005, "更新失败");
  934. }
  935. } catch (\Exception $e) {
  936. Db::rollback();
  937. return json_show(1005, $e->getMessage());
  938. }
  939. }
  940. //修改商品成本全部信息
  941. public function editGoodUp()
  942. {
  943. $this->post = $this->request->filter('trim')->post();
  944. $supcode = isset($this->post['spuCode']) && $this->post['spuCode'] != "" ? trim($this->post['spuCode']) : "";
  945. if ($supcode == "") {
  946. return json_show(1004, "参数spuCode不能为空");
  947. }
  948. $data = Db::name("good_basic")->where(["spuCode" => $supcode, "is_del" => 0])->find();
  949. if ($data == false) {
  950. return json_show(1004, "未找到商品数据");
  951. }
  952. $is_down = Db::name("good_platform")
  953. ->where(["spuCode" => $supcode, "is_del" => 0])
  954. ->where("exam_status", "not in", [1, 5])//exam_status=1待完善成本,8已下线,除了这两个状态外其他状态都不允许编辑
  955. ->find();
  956. if ($is_down != false) {
  957. return json_show(1004, "存在未下线商品数据");
  958. }
  959. if ($data['status'] != 6 && $data['status'] != 7 && $data['status'] != 8) {
  960. return json_show(1004, "商品状态有误");
  961. }
  962. $good_name = isset($this->post['good_name']) && $this->post['good_name'] != "" ? trim($this->post['good_name']) : "";
  963. if ($good_name == "") {
  964. return json_show(1004, "商品名称不能为空");
  965. }
  966. $cat_id = isset($this->post['cat_id']) && $this->post['cat_id'] != "" ? intval($this->post['cat_id']) : "";
  967. if ($cat_id == '') {
  968. return json_show(1004, "商品分类不能为空");
  969. }
  970. $brandid = isset($this->post['brandid']) && $this->post['brandid'] != "" ? intval($this->post['brandid']) : "0";
  971. // if($brandid==''){
  972. // return json_show(1004,"商品品牌不能为空");
  973. // }
  974. $unit = isset($this->post['unit']) && $this->post['unit'] != "" ? trim($this->post['unit']) : "";
  975. if ($unit == '') {
  976. return json_show(1004, "商品单位不能为空");
  977. }
  978. $good_type = isset($this->post['good_type']) && $this->post['good_type'] !== "" ? intval($this->post['good_type']) : "";
  979. if ($good_type === '') {
  980. return json_show(1004, "参数good_type不能为空");
  981. }
  982. $moq = 0;
  983. $customized = 0;
  984. if ($good_type == 1) {
  985. $moq = isset($this->post['moq']) && $this->post['moq'] !== "" ? intval($this->post['moq']) : "";
  986. if ($moq === '') {
  987. return json_show(1004, "定制商品起订量不能为空");
  988. }
  989. $customized = isset($this->post['customized']) && $this->post['customized'] !== "" ? intval($this->post['customized']) : "";
  990. if ($customized === '') {
  991. return json_show(1004, "参数customized不能为空");
  992. }
  993. }
  994. $is_exclusive = isset($this->post['is_exclusive']) && $this->post['is_exclusive'] !== "" ? intval($this->post['is_exclusive']) : "";
  995. if ($is_exclusive === '') {
  996. return json_show(1004, "参数is_exclusive不能为空");
  997. }
  998. // $customized = isset($this->post['customized'])&&$this->post['customized']!==""? intval($this->post['customized']):"";
  999. // if($customized===''){
  1000. // return json_show(1004,"参数customized不能为空");
  1001. // }
  1002. $tax = isset($this->post['tax']) && $this->post['tax'] !== "" ? intval($this->post['tax']) : "";
  1003. if ($tax === '') {
  1004. return json_show(1004, "参数tax不能为空");
  1005. }
  1006. $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] != "" ? trim($this->post['supplierNo']) : "";
  1007. if ($supplierNo == '') {
  1008. return json_show(1004, "参数supplierNo不能为空");
  1009. }
  1010. $good_size = isset($this->post['good_size']) && $this->post['good_size'] != "" ? trim($this->post['good_size']) : "";
  1011. if ($good_size == '') {
  1012. return json_show(1004, "参数good_size不能为空");
  1013. }
  1014. $company_id = isset($this->post['companyNo']) && $this->post['companyNo'] != "" ? trim($this->post['companyNo']) : "";
  1015. if ($company_id == '') {
  1016. return json_show(1004, "参数companyNo不能为空");
  1017. }
  1018. $is_auth = isset($this->post['is_auth']) && $this->post['is_auth'] !== "" ? intval($this->post['is_auth']) : "";
  1019. if ($is_auth === '') {
  1020. return json_show(1004, "参数is_auth不能为空");
  1021. }
  1022. $auth_img = isset($this->post['auth_img']) && $this->post['auth_img'] != "" ? trim($this->post['auth_img']) : "";
  1023. // if($auth_img==''){
  1024. // return json_show(1004,"商品不能为空");
  1025. // }
  1026. $after_sales = isset($this->post['after_sales']) && $this->post['after_sales'] != "" ? trim($this->post['after_sales']) : "";
  1027. if ($after_sales == "") {
  1028. return json_show(1004, "参数after_sales不能为空");
  1029. }
  1030. $craft_desc = isset($this->post['craft_desc']) && $this->post['craft_desc'] != "" ? trim($this->post['craft_desc']) : "";
  1031. $good_remark = isset($this->post['good_remark']) && $this->post['good_remark'] != "" ? trim($this->post['good_remark']) : "";
  1032. if ($good_remark === "") {
  1033. return json_show(1004, "参数good_remark不能为空");
  1034. }
  1035. $weight = isset($this->post['weight']) && $this->post['weight'] !== "" ? floatval($this->post['weight']) : "";
  1036. if ($weight === "") {
  1037. return json_show(1004, "参数weight不能为空");
  1038. }
  1039. $packing_way = isset($this->post['packing_way']) && $this->post['packing_way'] !== "" ? trim($this->post['packing_way']) : "";
  1040. if ($packing_way === "") {
  1041. return json_show(1004, "参数packing_way不能为空");
  1042. }
  1043. $packing_size = isset($this->post['packing_size']) && $this->post['packing_size'] !== "" ? trim($this->post['packing_size']) : "";
  1044. if ($packing_size === "") {
  1045. return json_show(1004, "参数packing_size不能为空");
  1046. }
  1047. $packing_spec = isset($this->post['packing_spec']) && $this->post['packing_spec'] !== "" ? trim($this->post['packing_spec']) : "";
  1048. if ($packing_spec === "") {
  1049. return json_show(1004, "参数packing_spec不能为空");
  1050. }
  1051. $packing_weight = isset($this->post['packing_weight']) && $this->post['packing_weight'] !== "" ? floatval($this->post['packing_weight']) : "";
  1052. if ($packing_weight === "") {
  1053. return json_show(1004, "参数packing_weight不能为空");
  1054. }
  1055. $packing_list = isset($this->post['packing_list']) && $this->post['packing_list'] !== "" ? trim($this->post['packing_list']) : "";
  1056. if ($packing_list === "") {
  1057. return json_show(1004, "参数packing_list不能为空");
  1058. }
  1059. $good_bar = isset($this->post['good_bar']) && $this->post['good_bar'] !== "" ? trim($this->post['good_bar']) : "";
  1060. $supply_area = isset($this->post['supply_area']) && $this->post['supply_area'] !== "" ? intval($this->post['supply_area']) : "";
  1061. if ($supply_area === "") {
  1062. return json_show(1004, "参数supply_area不能为空");
  1063. }
  1064. $delivery_place = isset($this->post['delivery_place']) && $this->post['delivery_place'] !== "" ? $this->post['delivery_place'] : "";
  1065. if ($delivery_place === "") {
  1066. return json_show(1004, "参数delivery_place不能为空");
  1067. }
  1068. $origin_place = isset($this->post['origin_place']) && $this->post['origin_place'] !== "" ? $this->post['origin_place'] : "";
  1069. if ($origin_place === "") {
  1070. return json_show(1004, "参数origin_place不能为空");
  1071. }
  1072. $delivery_day = isset($this->post['delivery_day']) && $this->post['delivery_day'] !== "" ? intval($this->post['delivery_day']) : "";
  1073. if ($delivery_day === "") {
  1074. return json_show(1004, "参数delivery_day不能为空");
  1075. }
  1076. $lead_time = isset($this->post['lead_time']) && $this->post['lead_time'] !== "" ? intval($this->post['lead_time']) : "0";
  1077. // if($lead_time===""){
  1078. // return json_show(1004,"参数lead_time不能为空");
  1079. // }
  1080. $sample_day = isset($this->post['sample_day']) && $this->post['sample_day'] !== "" ? intval($this->post['sample_day']) : "0";
  1081. // if($sample_day===""){
  1082. // return json_show(1004,"参数sample_day不能为空");
  1083. // }
  1084. $sample_fee = isset($this->post['sample_fee']) && $this->post['sample_fee'] !== "" ? floatval($this->post['sample_fee']) : "0";
  1085. $good_img = isset($this->post['good_img']) && $this->post['good_img'] != "" ? trim($this->post['good_img']) : "";
  1086. if ($good_img === "") {
  1087. return json_show(1004, "参数good_img不能为空");
  1088. }
  1089. $good_thumb_img = isset($this->post['good_thumb_img']) && $this->post['good_thumb_img'] !== "" ? trim($this->post['good_thumb_img']) : "";
  1090. if ($good_thumb_img === "") {
  1091. return json_show(1004, "参数good_thumb_img不能为空");
  1092. }
  1093. $good_info_img = isset($this->post['good_info_img']) && !empty($this->post['good_info_img']) ? trim($this->post['good_info_img']) : "";
  1094. if ($good_info_img === "") {
  1095. return json_show(1004, "参数good_info_img不能为空");
  1096. }
  1097. $cert_fee = isset($this->post['cert_fee']) && $this->post['cert_fee'] !== "" ? floatval($this->post['cert_fee']) : "0";
  1098. $packing_fee = isset($this->post['packing_fee']) && $this->post['packing_fee'] !== "" ? floatval($this->post['packing_fee']) : "0";
  1099. $cost_fee = isset($this->post['cost_fee']) && $this->post['cost_fee'] !== "" ? floatval($this->post['cost_fee']) : "0";
  1100. $mark_fee = isset($this->post['mark_fee']) && $this->post['mark_fee'] !== "" ? floatval($this->post['mark_fee']) : "0";
  1101. $demo_fee = isset($this->post['demo_fee']) && $this->post['demo_fee'] !== "" ? floatval($this->post['demo_fee']) : "0";
  1102. $open_fee = isset($this->post['open_fee']) && $this->post['open_fee'] !== "" ? floatval($this->post['open_fee']) : "0";
  1103. $noble_metal = isset($this->post['noble_metal']) && $this->post['noble_metal'] !== "" ? intval($this->post['noble_metal']) : "0";
  1104. $noble_weight = isset($this->post['noble_weight']) && $this->post['noble_weight'] !== "" ? floatval($this->post['noble_weight']) : "0";
  1105. $is_gold_price = isset($this->post['is_gold_price']) && $this->post['is_gold_price'] !== "" ? intval($this->post['is_gold_price']) : "0";
  1106. $market_price = isset($this->post['market_price']) && $this->post['market_price'] !== "" ? floatval($this->post['market_price']) : "";
  1107. $cgd_gold_price = isset($this->post['cgd_gold_price']) && $this->post['cgd_gold_price'] !== "" ? floatval($this->post['cgd_gold_price']) : "0";
  1108. if ($market_price === "") {
  1109. return json_show(1004, "参数market_price不能为空");
  1110. }
  1111. $nake_price = isset($this->post['nake_price']) && $this->post['nake_price'] !== "" ? floatval($this->post['nake_price']) : "0";
  1112. $config = isset($this->post['config']) && $this->post['config'] !== "" ? trim($this->post['config']) : "";
  1113. $other_config = isset($this->post['other_config']) && $this->post['other_config'] !== "" ? trim($this->post['other_config']) : "";
  1114. $is_diff = isset($this->post['is_diff']) && $this->post['is_diff'] !== "" ? intval($this->post['is_diff']) : "0";
  1115. $is_stock = isset($this->post['is_stock']) && $this->post['is_stock'] !== "" ? intval($this->post['is_stock']) : "0";
  1116. $stock_moq = isset($this->post['stock_moq']) && $this->post['stock_moq'] !== "" ? intval($this->post['stock_moq']) : "0";
  1117. if ($is_stock == 1 && $stock_moq == 0) {
  1118. return json_show(1004, "库存品备库起订量不能为零");
  1119. }
  1120. // $is_step = isset($this->post['is_step'])&&$this->post['is_step']!==""? intval($this->post['is_step']):"";
  1121. // if($is_step===""){
  1122. // return json_show(1004,"参数is_step不能为空");
  1123. // }
  1124. $good_ladder = isset($this->post['good_ladder']) && !empty($this->post['good_ladder']) ? $this->post['good_ladder'] : "";
  1125. // if($is_step==1 && $good_ladder==""){
  1126. // return json_show(1004,"启用阶梯,阶梯价不能为空");
  1127. // }
  1128. $speclist = isset($this->post['speclist']) && !empty($this->post['speclist']) ? $this->post['speclist'] : "";
  1129. $is_support_barter = isset($this->post['is_support_barter']) && $this->post['is_support_barter'] !== "" ? intval($this->post['is_support_barter']) : 1;
  1130. $uid = $this->request->user['uid'];
  1131. $nickname = $this->request->user['nickname'];
  1132. Db::startTrans();
  1133. try {
  1134. $temp = [
  1135. "good_name" => $good_name,
  1136. "cat_id" => $cat_id,
  1137. 'brand_id' => $brandid,
  1138. "good_unit" => $unit,
  1139. "good_type" => $good_type,
  1140. "companyNo" => $company_id,
  1141. "moq" => $moq,
  1142. "is_exclusive" => $is_exclusive,
  1143. "customized" => $customized,
  1144. "tax" => $tax,
  1145. "supplierNo" => $supplierNo,
  1146. "is_auth" => $is_auth,
  1147. "good_size" => $good_size,
  1148. "auth_img" => $auth_img,
  1149. "after_sales" => $after_sales,
  1150. "craft_desc" => $craft_desc,
  1151. "good_remark" => $good_remark,
  1152. "weight" => $weight,
  1153. "packing_way" => $packing_way,
  1154. "packing_size" => $packing_size,
  1155. "packing_spec" => $packing_spec,
  1156. "packing_list" => $packing_list,
  1157. "packing_weight" => $packing_weight,
  1158. "good_bar" => $good_bar,
  1159. "supply_area" => $supply_area,
  1160. "delivery_place" => $delivery_place,
  1161. "origin_place" => $origin_place,
  1162. "delivery_day" => $delivery_day,
  1163. "lead_time" => $lead_time,
  1164. "sample_day" => $sample_day,
  1165. "sample_fee" => $sample_fee,
  1166. "good_img" => $good_img,
  1167. "good_thumb_img" => $good_thumb_img,
  1168. "good_info_img" => $good_info_img,
  1169. "cert_fee" => $cert_fee,
  1170. "packing_fee" => $packing_fee,
  1171. "is_diff" => $is_diff,
  1172. "config" => $config,
  1173. "other_config" => $other_config,
  1174. "is_stock" => $is_stock,
  1175. "cost_fee" => $cost_fee,
  1176. "mark_fee" => $mark_fee,
  1177. "demo_fee" => $demo_fee,
  1178. "open_fee" => $open_fee,
  1179. "noble_metal" => $noble_metal,
  1180. "noble_weight" => $noble_weight,
  1181. "is_gold_price" => $is_gold_price,
  1182. "market_price" => $market_price,
  1183. "nake_price" => $nake_price,
  1184. "cgd_gold_price" => $cgd_gold_price,
  1185. "is_step" => count($good_ladder) > 1 ? 1 : 0,
  1186. "stock_moq" => $stock_moq,
  1187. "status" => "0",
  1188. "updatetime" => date("Y-m-d H:i:s"),
  1189. 'is_support_barter' => $is_support_barter
  1190. ];
  1191. $field = array_diff_assoc($temp, $data);
  1192. $temp['field_change'] = empty($field) ? "" : json_encode(array_keys($field));
  1193. $up = Db::name("good_basic")->where(["spuCode" => $supcode, "is_del" => 0])->save($temp);
  1194. $var = array_diff($temp, $data);
  1195. $json = json_encode($var, JSON_UNESCAPED_UNICODE);
  1196. $dat = json_encode($data, JSON_UNESCAPED_UNICODE);
  1197. if ($up) {
  1198. ChangeLog::logAdd(3, $data['spuCode'], $dat, $json, ['id' => $uid, 'nickname' => $nickname], $this->post);
  1199. //修改状态,添加待办
  1200. ActionLog::logAdd(['id' => $uid, 'nickname' => $nickname], [
  1201. "order_code" => $supcode,//咨询单详情编号
  1202. "status" => $data['status'],//这里的status是之前的值
  1203. "action_remark" => '',//备注
  1204. "action_type" => "create"//新建create,编辑edit,更改状态status
  1205. ], "SPCB", 0, $temp);
  1206. ProcessOrder::AddProcess(['id' => $uid, 'nickname' => $nickname], [
  1207. "order_type" => 'SPCB',
  1208. "order_code" => $supcode,//咨询单详情编号
  1209. "order_id" => $data['id'],
  1210. "order_status" => 0,
  1211. "before_status" => 0,
  1212. 'holder_id' => $data['createrid'],
  1213. 'person_id' => Db::name('supplier')->where(['code' => $this->request->user['supplierNo'], 'is_del' => 0])->value('personid'),
  1214. ]);
  1215. if ($speclist !== "" && !empty($speclist)) {
  1216. foreach ($speclist as $value) {
  1217. $lemp = [];
  1218. isset($value["id"]) && $value["id"] != '' ? $lemp['id'] = $value['id'] : "";
  1219. $lemp['spuCode'] = $supcode;
  1220. $lemp['spec_id'] = $value['spec_id'];
  1221. $lemp['spec_value_id'] = $value['spec_value_id'];
  1222. $lemp['is_del'] = isset($value['is_del']) ? $value['is_del'] : 0;
  1223. isset($value["id"]) && $value["id"] != '' ? "" : $lemp['addtime'] = date("Y-m-d H:i:s");
  1224. $lemp['updatetime'] = date("Y-m-d H:i:s");
  1225. $count = Db::name("good_spec")->save($lemp);
  1226. if ($count == false) {
  1227. Db::rollback();
  1228. return json_show(1004, "商品规格值修改失败");
  1229. }
  1230. }
  1231. }
  1232. if ($good_ladder !== "" && !empty($good_ladder)) {
  1233. // $user =GetUserInfo($this->post['token']);//获取用户信息,下面更新成本表的创建人
  1234. $top_cat_id = made($cat_id);//获取所有分类
  1235. $top_cat_id = isset($top_cat_id[0]['id']) ? $top_cat_id[0]['id'] : 0;//获取顶级分类id
  1236. foreach ($good_ladder as $value) {
  1237. $lemp = [];
  1238. isset($value["id"]) && $value["id"] != '' ? $lemp['id'] = $value['id'] : "";
  1239. $lemp['spuCode'] = $supcode;
  1240. $lemp['min_num'] = $value['min_num'];
  1241. $lemp['nake_fee'] = $value['nake_fee'];
  1242. $lemp['cost_fee'] = $value['cost_fee'];
  1243. $lemp['delivery_fee'] = $value['delivery_fee'];
  1244. $lemp['cert_fee'] = $value['cert_fee'];
  1245. $lemp['mark_fee'] = $value['mark_fee'];
  1246. $lemp['package_fee'] = $value['package_fee'];
  1247. $lemp['other_fee'] = $value['other_fee'];
  1248. if ($is_gold_price == 1 && $top_cat_id == 6) {
  1249. // $gold =Db::name("gold_price1")->where(["type"=>$noble_metal,"status"=>1,"is_del"=>0])
  1250. // ->order("addtime desc")->find();
  1251. //$lemp['nake_total'] =$noble_weight*$gold['price'] + $value['cost_fee']*$noble_weight+$value['mark_fee']+$value['package_fee']+$value['cert_fee']+$value['nake_fee']+$value['delivery_fee']+$value['other_fee'];
  1252. //成本合计=贵金属重量*供应商采购金价 + 工艺费*贵金属重量+加标费+包装费+证书费+成本裸价+运费+其他费用
  1253. //成本总计启用实时金价时,采用供应商实时金价
  1254. $lemp['nake_total'] = $noble_weight * $cgd_gold_price + $value['cost_fee'] * $noble_weight +
  1255. $value['mark_fee'] + $value['package_fee'] + $value['cert_fee'] + $value['nake_fee'] + $value['delivery_fee'] + $value['other_fee'];
  1256. } else {
  1257. $lemp['nake_total'] = $value['nake_fee'] + $value['delivery_fee'] + $value['cert_fee'] + $value['mark_fee'] + $value['package_fee'] + $value['other_fee'];
  1258. }
  1259. $lemp['creater_id'] = $this->request->user['uid'];
  1260. $lemp['creater'] = $this->request->user['nickname'];
  1261. $lemp['is_del'] = isset($value['is_del']) ? $value['is_del'] : 0;
  1262. isset($value["id"]) && $value["id"] != '' ? "" : $lemp['addtime'] = date("Y-m-d H:i:s");
  1263. $lemp['updatetime'] = date("Y-m-d H:i:s");
  1264. $count = Db::name("good_nake")->save($lemp);
  1265. if ($count == false) {
  1266. Db::rollback();
  1267. return json_show(1004, "商品规成本修改失败");
  1268. }
  1269. }
  1270. }
  1271. Db::commit();
  1272. return json_show(0, "更新成功");
  1273. } else {
  1274. Db::rollback();
  1275. return json_show(1005, "更新失败");
  1276. }
  1277. } catch (\Exception $e) {
  1278. Db::rollback();
  1279. return json_show(1004, $e->getMessage());
  1280. }
  1281. }
  1282. //获取商品详情
  1283. public function read()
  1284. {
  1285. $this->post = $this->request->filter('trim')->post();
  1286. $supcode = isset($this->post['spuCode']) && $this->post['spuCode'] != "" ? trim($this->post['spuCode']) : "";
  1287. if ($supcode == "") {
  1288. return json_show(1004, "参数spuCode不能为空");
  1289. }
  1290. $data = Db::name("good_basic")->where(["spuCode" => $supcode, "is_del" => 0])->find();
  1291. if ($data == false) {
  1292. return json_show(1004, "未找到商品数据");
  1293. }
  1294. $unit = Db::name("unit")->where(["id" => $data['good_unit']])->find();
  1295. $data['unit'] = isset($unit['unit']) ? $unit['unit'] : '';
  1296. $data['cat_info'] = made($data['cat_id'], []);
  1297. $spec = Db::name("good_spec")->where(["spuCode" => $supcode, "is_del" => 0])->select()->toArray();
  1298. $supplier = Db::name("supplier")->where(["code" => $data['supplierNo']])->find();
  1299. $data['supplierName'] = isset($supplier['name']) ? $supplier['name'] : "";
  1300. $supplier = Db::name("supplier")->where(["code" => $data['supplierNo']])->find();
  1301. $data['supplierName'] = isset($supplier['name']) ? $supplier['name'] : "";
  1302. $company = Db::name("business")->where(["companyNo" => $data['companyNo']])->find();
  1303. $data['company'] = isset($company['company']) ? $company['company'] : "";
  1304. $data['field_change'] = $data['field_change'] != '' ? json_decode($data['field_change']) : "";
  1305. if ($data['brand_id'] != 0) {
  1306. $brand = Db::name("brand")->where(["id" => $data['brand_id']])->find();
  1307. $data["brand_name"] = isset($brand['brand_name']) ? $brand['brand_name'] : "";
  1308. } else {
  1309. $data["brand_name"] = "";
  1310. $data["brand_id"] = "";
  1311. }
  1312. $excluse = makeExcluse($data['is_exclusive']);
  1313. $data['exclusive'] = $excluse;
  1314. $data['noble_name'] = isset($data['noble_metal']) && $data['noble_metal'] != 0 ? $this->noble[$data['noble_metal']] : "";
  1315. $data["good_info_img"] = $data['good_info_img'] != "" ? $data['good_info_img'] : '';
  1316. $data["good_img"] = $data['good_img'] != "" ? $data['good_img'] : [];
  1317. $gold = [];
  1318. if ($data['is_gold_price'] == 1) {
  1319. $gold = Db::name("gold_price1")->where(["type" => $data['noble_metal'], "status" => 1, "is_del" => 0])->order("addtime desc")->find();
  1320. }
  1321. $data['gold_price'] = isset($gold["price"]) ? $gold["price"] : 0;
  1322. $speclist = [];
  1323. if (!empty($spec)) {
  1324. foreach ($spec as $value) {
  1325. $temp = [];
  1326. $temp['id'] = $value['id'];
  1327. $temp['spuCode'] = $value['spuCode'];
  1328. $temp['spec_id'] = $value['spec_id'];
  1329. $temp['spec_value_id'] = $value['spec_value_id'];
  1330. $temp['is_del'] = $value['is_del'];
  1331. $sp = Db::name("specs")->where(["id" => $value['spec_id']])->find();
  1332. $temp['spec_name'] = isset($sp["spec_name"]) ? $sp["spec_name"] : "";
  1333. $spv = Db::name("spec_value")->where(["id" => $value['spec_value_id']])->find();
  1334. $temp['spec_value'] = isset($spv["spec_value"]) ? $spv["spec_value"] : "";
  1335. $speclist[] = $temp;
  1336. }
  1337. }
  1338. $data["speclist"] = empty($speclist) ? [] : $speclist;
  1339. // $nake=[];
  1340. $nakelist = Db::name("good_nake")->where(['spuCode' => $supcode, "is_del" => 0])->select()->toArray();
  1341. // $catinfo = Db::name("cat")->where(["id"=>$data['cat_id']])->find();
  1342. // $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  1343. $nakearry = [];
  1344. if (!empty($nakelist)) {
  1345. foreach ($nakelist as $value) {
  1346. $nakearry[] = $value;
  1347. }
  1348. }
  1349. $data["nakelist"] = $nakearry;
  1350. return json_show(0, "获取成功", $data);
  1351. }
  1352. //创建规格值
  1353. public function createSpec()
  1354. {
  1355. $this->post = $this->request->filter('trim')->post();
  1356. $spec_id = isset($this->post['spec_id']) && $this->post['spec_id'] !== "" ? intval($this->post['spec_id']) : "";
  1357. if ($spec_id == "") {
  1358. return json_show(1002, "参数spec_id不能为空");
  1359. }
  1360. $spec_value = isset($this->post['spec_value']) && $this->post['spec_value'] !== "" ? trim($this->post['spec_value']) : "";
  1361. if ($spec_value == "") {
  1362. return json_show(1002, "参数spec_value不能为空");
  1363. }
  1364. $id_is_empty = Db::name('spec_value')
  1365. ->field('id')
  1366. ->where([
  1367. 'spec_id' => $spec_id,
  1368. 'spec_value' => $spec_value,
  1369. 'is_del' => 0
  1370. ])->find();
  1371. if ($id_is_empty) return json_show(1005, '数据库已存在该规格值');
  1372. else {
  1373. $data = [
  1374. "spec_id" => $spec_id,
  1375. "spec_value" => $spec_value,
  1376. "is_del" => 0,
  1377. "addtime" => date("Y-m-d H:i:s"),
  1378. "updatetime" => date("Y-m-d H:i:s")
  1379. ];
  1380. $info = Db::name("spec_value")->insert($data);
  1381. if ($info) return json_show(0, "新建成功");
  1382. else return json_show(1002, "新建失败");
  1383. }
  1384. }
  1385. //所有规格值
  1386. public function allSpec()
  1387. {
  1388. $spec_id = $this->request->filter('trim')->post('spec_id/d', 0);
  1389. if ($spec_id == 0) {
  1390. return json_show(1002, "参数spec_id不能为空");
  1391. }
  1392. $info = Db::name('spec_value')
  1393. ->where(['spec_id' => $spec_id, 'is_del' => 0])
  1394. ->select()
  1395. ->toArray();
  1396. return json_show(0, "获取成功", $info);
  1397. }
  1398. //分类信息
  1399. public function catInfo()
  1400. {
  1401. // $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
  1402. $id = $this->request->filter('trim')->post('id/d', 0);
  1403. if ($id == "") {
  1404. return json_show(1002, "参数id不能为空");
  1405. }
  1406. $idinfo = Db::name('cat')->where(['id' => $id])->find();
  1407. if ($idinfo == "") {
  1408. return json_show(1002, "未找到数据");
  1409. }
  1410. $info = Db::name('cat_specs')->where(['cat_id' => $idinfo['id'], 'is_del' => 0])->column('specs_id');
  1411. $temp = Db::name('specs')->where(['id' => $info, 'is_del' => 0])->field("id,spec_name")->select();
  1412. //$idinfo['cat_id']=$info['cat_id'];
  1413. $idinfo['spec'] = $temp;
  1414. // $idinfo['specs_id']=$info;
  1415. return json_show(0, "获取成功", $idinfo);
  1416. }
  1417. //实时金价列表
  1418. public function goldPriceLastList()
  1419. {
  1420. $this->post = $this->request->filter('trim')->post();
  1421. $where = [['g.is_del', '=', 0]];
  1422. $type = isset($this->post['type']) && $this->post['type'] != "" ? intval($this->post['type']) : "";
  1423. if ($type !== "") $where[] = ['g.type', '=', $type];
  1424. $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  1425. if ($company_name !== "") $where[] = ["g.action_id", 'in', get_company_item_user_by_name($company_name)];
  1426. $ids = Db::name("gold_price1")
  1427. ->where(['is_del' => 0])
  1428. ->group("type")
  1429. ->column("max(id) as id");
  1430. $where[] = ['g.id', 'in', $ids];
  1431. $list = Db::name("gold_price1")
  1432. ->alias('g')
  1433. ->where($where)
  1434. ->select()
  1435. ->toArray();
  1436. $all_createrid = array_column($list,'action_id');
  1437. $item = get_company_name_by_uid($all_createrid);
  1438. $data = [];
  1439. foreach ($list as $value) {
  1440. $value['type_cn'] = $this->gold[$value['type']];
  1441. $value['company_name'] = $item[$value['action_id']]??'';
  1442. $data[] = $value;
  1443. }
  1444. return json_show(0, "获取成功", $data);
  1445. }
  1446. //贵金属种类列表
  1447. public function linst()
  1448. {
  1449. $data = [];
  1450. foreach ($this->gold as $key => $value) {
  1451. $v = [];
  1452. $v['type'] = $key;
  1453. $v['type_cn'] = $value;
  1454. $data[] = $v;
  1455. }
  1456. return json_show(0, "获取成功", $data);
  1457. }
  1458. //分类列表
  1459. public function wlist()
  1460. {
  1461. $this->post = $this->request->filter('trim')->post();
  1462. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
  1463. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
  1464. $where = [["is_del", "=", 0], ['level', "=", 3]];
  1465. $cat_name = isset($this->post['cat_name']) && $this->post['cat_name'] !== "" ? trim($this->post['cat_name']) : "";
  1466. if ($cat_name !== "") {
  1467. $where[] = ['cat_name', "like", "%$cat_name%"];
  1468. }
  1469. $search = isset($this->post['search']) && $this->post['search'] !== "" ? trim($this->post['search']) : "";
  1470. if ($search !== "") {
  1471. $where[] = ['search', "like", "%$search%"];
  1472. }
  1473. $pid = isset($this->post['pid']) && $this->post['pid'] !== "" ? intval($this->post['pid']) : "";
  1474. if ($pid !== "") {
  1475. $where[] = ['pid', "=", $pid];
  1476. }
  1477. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  1478. if ($status !== "") {
  1479. $where[] = ['status', "=", $status];
  1480. }
  1481. $count = Db::name("cat")->where($where)->count();
  1482. $total = ceil($count / $size);
  1483. $page = $page >= $total ? $total : $page;
  1484. $list = Db::name('cat')->where($where)->page($page, $size)->select();
  1485. $data = [];
  1486. foreach ($list as $value) {
  1487. $temp = isset($value['id']) && $value['id'] != 0 ? made($value['id']) : [];
  1488. $value['item'] = array_column($temp, 'id');
  1489. $data[] = $value;
  1490. }
  1491. return json_show(0, "获取成功", ['list' => $data, 'count' => $count]);
  1492. }
  1493. //分类列表-全部
  1494. public function title()
  1495. {
  1496. $this->post = $this->request->filter('trim')->post();
  1497. $where = [["is_del", "=", 0]];
  1498. $cat_name = isset($this->post['cat_name']) && $this->post['cat_name'] !== "" ? trim($this->post['cat_name']) : "";
  1499. if ($cat_name !== "") $where[] = ['cat_name', "like", "%$cat_name%"];
  1500. $pid = isset($this->post['pid']) && $this->post['pid'] !== "" ? intval($this->post['pid']) : "";
  1501. if ($pid !== "") $where[] = ["pid", "=", $pid];
  1502. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  1503. if ($status !== "") $where[] = ['status', "=", $status];
  1504. $list = Db::name('cat')
  1505. ->where($where)
  1506. ->select()
  1507. ->toArray();
  1508. return json_show(0, "获取成功", $list);
  1509. }
  1510. //判断是否允许修改成本信息和基础信息
  1511. public function checkIsUpdate()
  1512. {
  1513. $spuCode = $this->request->post('spuCode', '', 'trim');
  1514. if ($spuCode == '') return json_show(1004, '成本商品编号不能为空');
  1515. $is_allow_update = 1;
  1516. //检查是否有上线记录
  1517. $rs = Db::name('good_platform')
  1518. ->field('id')
  1519. ->where(['spuCode' => $spuCode, 'is_del' => 0])
  1520. ->whereNotIn('exam_status', [0, 5])
  1521. ->find();
  1522. if (!empty($rs)) $is_allow_update = 0;
  1523. else {
  1524. $rs = PlatformYouzan::field('id')
  1525. ->where(['spuCode' => $spuCode, 'is_del' => PlatformYouzan::$del_normal])
  1526. ->whereNotIn('exam_status', [PlatformYouzan::$exam_status_8, PlatformYouzan::$exam_status_2])
  1527. ->findOrEmpty()
  1528. ->isEmpty();
  1529. if (!$rs) $is_allow_update = 0;
  1530. }
  1531. return json_show(0, '请求成功', ['is_allow_update' => $is_allow_update]);
  1532. }
  1533. //上线商品复制
  1534. public function copy()
  1535. {
  1536. $this->post = $this->request->filter('trim')->post();
  1537. $supcode = isset($this->post['spuCode']) && $this->post['spuCode'] != "" ? trim($this->post['spuCode']) : "";
  1538. if ($supcode == "") {
  1539. return json_show(1004, "参数spuCode不能为空");
  1540. }
  1541. $data = Db::name("good_basic")->where(["spuCode" => $supcode, "is_del" => 0])->find();
  1542. if ($data == false) {
  1543. return json_show(1004, "未找到商品数据");
  1544. }
  1545. // $token = isset($this->post['token']) && $this->post['token'] != '' ? trim($this->post['token']) : "";
  1546. // if ($token == '') {
  1547. // return json_show(105, "参数token不能为空");
  1548. // }
  1549. // $user =GetUserInfo($token);
  1550. // if(empty($user)||$user['code']!=0){
  1551. // return json_show(102,"用户数据不存在");
  1552. // }
  1553. $createrid = $this->request->user['uid'];
  1554. $creater = $this->request->user['nickname'];
  1555. $nake = Db::name("good_nake")->where(["spuCode" => $supcode, "is_del" => 0])->select()->toArray();
  1556. $ladd = [];
  1557. $newCode = makeNo("SKU");
  1558. if (!empty($nake)) {
  1559. foreach ($nake as $value) {
  1560. $tmp = [];
  1561. $tmp['spuCode'] = $newCode;
  1562. $tmp['min_num'] = $value['min_num'];
  1563. $tmp['nake_fee'] = $value['nake_fee'];
  1564. $tmp['cost_fee'] = $value['cost_fee'];
  1565. $tmp['delivery_fee'] = $value['delivery_fee'];
  1566. $tmp['cert_fee'] = $value['cert_fee'];
  1567. $tmp['mark_fee'] = $value['mark_fee'];
  1568. $tmp['package_fee'] = $value['package_fee'];
  1569. $tmp['other_fee'] = $value['other_fee'];
  1570. $tmp['nake_total'] = $value['nake_total'];
  1571. $tmp['creater_id'] = $createrid;
  1572. $tmp['creater'] = $creater;
  1573. $tmp['is_del'] = $value['is_del'];
  1574. $tmp['addtime'] = date("Y-m-d H:i:s");
  1575. $tmp['updatetime'] = date("Y-m-d H:i:s");
  1576. $ladd[] = $tmp;
  1577. }
  1578. }
  1579. $spec = Db::name("good_spec")
  1580. ->where(["spuCode" => $supcode, "is_del" => 0])
  1581. ->select()
  1582. ->toArray();
  1583. $specArr = [];
  1584. if (!empty($spec)) {
  1585. foreach ($spec as $value) {
  1586. $tmp = [];
  1587. $tmp['spuCode'] = $newCode;
  1588. $tmp['spec_id'] = $value['spec_id'];
  1589. $tmp['spec_value_id'] = $value['spec_value_id'];
  1590. $tmp['is_del'] = $value['is_del'];
  1591. $tmp['addtime'] = date("Y-m-d H:i:s");
  1592. $tmp['updatetime'] = date("Y-m-d H:i:s");
  1593. $specArr[] = $tmp;
  1594. }
  1595. }
  1596. Db::startTrans();
  1597. try {
  1598. unset($data['id']);
  1599. $data['spuCode'] = $newCode;
  1600. $data['createrid'] = $createrid;
  1601. $data['creater'] = $creater;
  1602. $data['status'] = 7;
  1603. $data['addtime'] = date("Y-m-d H:i:s");
  1604. $data['updatetime'] = date("Y-m-d H:i:s");
  1605. $cre = Db::name("good_basic")->insert($data);
  1606. if ($cre) {
  1607. //修改状态,添加待办
  1608. ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
  1609. "order_code" => $newCode,//咨询单详情编号
  1610. "status" => 0,//这里的status是之前的值
  1611. "action_remark" => '',//备注
  1612. "action_type" => "create"//新建create,编辑edit,更改状态status
  1613. ], "SPCB", 7, $data);
  1614. ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
  1615. "order_type" => 'SPCB',
  1616. "order_code" => $newCode,//咨询单详情编号
  1617. "order_id" => Db::name("good_basic")->getLastInsID(),
  1618. "order_status" => 7,
  1619. "before_status" => 0,
  1620. 'holder_id' => $data['createrid'],
  1621. 'person_id' => Db::name('supplier')->where(['code' => $this->request->user['supplierNo'], 'is_del' => 0])->value('personid'),
  1622. ]);
  1623. if (!empty($ladd)) {
  1624. $na = Db::name("good_nake")->insertAll($ladd);
  1625. if ($na == 0) {
  1626. Db::rollback();
  1627. return json_show(1005, "成本数据复制失败");
  1628. }
  1629. }
  1630. if (!empty($specArr)) {
  1631. $sp = Db::name("good_spec")->insertAll($specArr);
  1632. if ($sp == 0) {
  1633. Db::rollback();
  1634. return json_show(1005, "规格数据复制失败");
  1635. }
  1636. }
  1637. Db::commit();
  1638. return json_show(0, "复制数据成功", ["spuCode" => $newCode]);
  1639. } else {
  1640. Db::rollback();
  1641. return json_show(1005, "数据复制失败");
  1642. }
  1643. } catch (\Exception $e) {
  1644. Db::rollback();
  1645. return json_show(1004, $e->getMessage());
  1646. }
  1647. }
  1648. //上线商品详情
  1649. public function info()
  1650. {
  1651. $this->post = $this->request->filter('trim')->post();
  1652. $skucode = isset($this->post['skuCode']) && $this->post['skuCode'] != "" ? trim($this->post['skuCode']) : "";
  1653. if ($skucode == "") {
  1654. return json_show(1005, "参数skuCode不能为空");
  1655. }
  1656. $good_platform = Db::name("good_platform")->where(['skuCode' => $skucode, "is_del" => 0])->find();
  1657. if ($good_platform == false) {
  1658. return json_show(1004, "未找到商品数据");
  1659. }
  1660. $data = Db::name("good")->where(["spuCode" => $good_platform['spuCode'], "is_del" => 0])->find();
  1661. if ($data == false) {
  1662. return json_show(1004, "未找到商品数据");
  1663. }
  1664. $plat = Db::name("platform")->where(["id" => $good_platform['platform_code']])->find();
  1665. $data['skuCode'] = $good_platform['skuCode'];
  1666. $data['platform_code'] = $good_platform['id'];
  1667. $data['platform_code_en'] = isset($plat['platform_code']) ? $plat['platform_code'] : "";
  1668. $data['platform_name'] = isset($plat['platform_name']) ? $plat['platform_name'] : "";
  1669. $data['online_reason'] = $good_platform['online_reason'];
  1670. $data['online_time'] = $good_platform['online_time'];
  1671. $data['online_remark'] = $good_platform['online_remark'];
  1672. $data['exam_status'] = $good_platform['exam_status'];
  1673. $data['is_online'] = $good_platform['is_online'];
  1674. $data['plat_code'] = $good_platform['plat_code'];
  1675. $data['exclusive'] = makeExcluse($data['is_exclusive']);
  1676. $unit = Db::name("unit")->where(["id" => $data['good_unit']])->find();
  1677. $data['unit'] = isset($unit['unit']) ? $unit['unit'] : '';
  1678. $data['cat_info'] = made($data['cat_id'], []);
  1679. $spec = Db::name("good_spec")->where(["spuCode" => $good_platform['spuCode'], "is_del" => 0])->select()->toArray();
  1680. $supplier = Db::name("supplier")->where(["code" => $data['supplierNo']])->find();
  1681. $data['supplierName'] = isset($supplier['name']) ? $supplier['name'] : "";
  1682. $data['noble_name'] = isset($data['noble_metal']) && $data['noble_metal'] != 0 ? $this->noble[$data['noble_metal']] : "";
  1683. $company = Db::name("business")->where(["companyNo" => $data['companyNo']])->find();
  1684. $data['company'] = isset($company['company']) ? $company['company'] : "";
  1685. if ($data['brand_id'] != 0) {
  1686. $brand = Db::name("brand")->where(["id" => $data['brand_id']])->find();
  1687. $data["brand_name"] = isset($brand['brand_name']) ? $brand['brand_name'] : "";
  1688. } else {
  1689. $data["brand_name"] = "";
  1690. $data["brand_id"] = "";
  1691. }
  1692. $data['origin_place_cn'] = "";
  1693. $data['delivery_place_cn'] = "";
  1694. if ($data['delivery_place'] !== "") {
  1695. $place = ["provice_code" => "", "city_code" => "", "area_code" => ""];
  1696. list($place['provice_code'], $place['city_code'], $place['area_code']) = explode(",", $data['delivery_place']);
  1697. $data['delivery_place_cn'] = GetAddr(json_encode($place));
  1698. }
  1699. if ($data['origin_place'] !== "") {
  1700. $place = ["provice_code" => "", "city_code" => "", "area_code" => ""];
  1701. list($place['provice_code'], $place['city_code'], $place['area_code']) = explode(",", $data['origin_place']);
  1702. $data['origin_place_cn'] = GetAddr(json_encode($place));
  1703. }
  1704. $excluse = makeExcluse($data['is_exclusive']);
  1705. $data['exclusive'] = $excluse;
  1706. $data["good_info_img"] = $data['good_info_img'] != "" ? $data['good_info_img'] : [];
  1707. $data["good_img"] = $data['good_img'] != "" ? $data['good_img'] : [];
  1708. $speclist = [];
  1709. if (!empty($spec)) {
  1710. foreach ($spec as $value) {
  1711. $temp = [];
  1712. $temp['id'] = $value['id'];
  1713. $temp['spuCode'] = $value['spuCode'];
  1714. $temp['spec_id'] = $value['spec_id'];
  1715. $temp['spec_value_id'] = $value['spec_value_id'];
  1716. $temp['is_del'] = $value['is_del'];
  1717. $sp = Db::name("specs")->where(["id" => $value['spec_id']])->find();
  1718. $temp['spec_name'] = isset($sp["spec_name"]) ? $sp["spec_name"] : "";
  1719. $spv = Db::name("spec_value")->where(["id" => $value['spec_value_id']])->find();
  1720. $temp['spec_value'] = isset($spv["spec_value"]) ? $spv["spec_value"] : "";
  1721. $speclist[] = $temp;
  1722. }
  1723. }
  1724. $data["speclist"] = empty($speclist) ? [] : $speclist;
  1725. $ladder = Db::name("good_ladder")->where(['skuCode' => $skucode, "is_del" => 0])->select()->toArray();
  1726. $data["ladderlist"] = !empty($ladder) ? $ladder : [];
  1727. $nakelist = Db::name("good_nake")->where(['spuCode' => $good_platform['spuCode'], "is_del" => 0])->select()->toArray();
  1728. // $catinfo = Db::name("cat")->where(["id"=>$data['cat_id']])->find();
  1729. $cat_top_list = $data['cat_info'];
  1730. $cat_top_id = isset($cat_top_list[0]['id']) ? $cat_top_list[0]['id'] : 0;
  1731. // $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  1732. $gold_price = 0;
  1733. if ($data['is_gold_price'] == 1 && $cat_top_id == 6) {
  1734. $gold_price = Db::name("gold_price1")->where(["type" => $data['noble_metal'], "status" => 1, "is_del" => 0])->order("addtime desc")->value('price', 0);
  1735. }
  1736. $data['gold_price'] = $gold_price;
  1737. $nakearry = [];
  1738. if (!empty($nakelist)) {
  1739. //实时金价
  1740. foreach ($nakelist as $value) {
  1741. $value['sale_price'] = $value['nake_total'];
  1742. //计算最终售价
  1743. if ($data['is_gold_price'] == 1 && $cat_top_id == 6) {
  1744. //普通商品:直接用财务提交的售价字段;
  1745. //贵金属( 商品重量* 最新金价 + 工艺费(财务定价提交的)* 商品重量+包装费+加标费+证书费+产品裸价+其他费用)=商品库商品直接下单的售价
  1746. $value['sale_price'] = ($data['weight'] * $gold_price + $value['cost_fee'] * $data['weight'] + $value['package_fee'] + $value['mark_fee'] + $value['cert_fee'] + $value['nake_fee'] + $value['other_fee']);
  1747. }
  1748. $nakearry[] = $value;
  1749. }
  1750. }
  1751. $proof = Db::name("good_proof")->where(["spuCode" => $good_platform['spuCode'], "is_del" => 0])->order("updatetime desc")->field("id,proof_type,proof_url")->find();
  1752. $data['proof'] = isset($proof) && $proof != false ? $proof : [];
  1753. $data["nakelist"] = $nakearry;
  1754. //补充采购员字段
  1755. //成本表里的创建人,也是线上商品的采购人,为了防止混淆,给creater取个别名
  1756. $temp_basic_info = Db::name('good_basic')
  1757. ->field('id,createrid purchase_id,creater purchase')
  1758. ->where(['spuCode' => $data['spuCode'], 'is_del' => 0])
  1759. ->find();
  1760. $data['purchase_id'] = $temp_basic_info['purchase_id'];
  1761. $data['purchase'] = $temp_basic_info['purchase'];
  1762. return json_show(0, "获取成功", $data);
  1763. }
  1764. }