Good.php 91 KB

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