Good.php 99 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867
  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. ->field('gb.*,u.itemid')
  137. ->leftJoin("depart_user u", "u.uid=gb.chargerid AND u.is_del=0")
  138. ->where($where)
  139. ->page($page, $size)
  140. ->order("addtime desc")
  141. ->select()
  142. ->toArray();
  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' => 6])//exam_status==6表示上线审核成功
  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'] = implode('/', array_column(GetPart($value['itemid']), 'name'));
  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", "<>", 8)->find();
  529. if ($is_down != false) {
  530. return json_show(1004, "存在未下线商品数据");
  531. }
  532. $good_name = isset($this->post['good_name']) && $this->post['good_name'] != "" ? trim($this->post['good_name']) : "";
  533. if ($good_name == "") {
  534. return json_show(1004, "商品名称不能为空");
  535. }
  536. $cat_id = isset($this->post['cat_id']) && $this->post['cat_id'] != "" ? intval($this->post['cat_id']) : "";
  537. if ($cat_id == '') {
  538. return json_show(1004, "商品分类不能为空");
  539. }
  540. $brandid = isset($this->post['brandid']) && $this->post['brandid'] != "" ? intval($this->post['brandid']) : "0";
  541. // if($brandid==''){
  542. // return json_show(1004,"商品品牌不能为空");
  543. // }
  544. $unit = isset($this->post['unit']) && $this->post['unit'] != "" ? trim($this->post['unit']) : "";
  545. if ($unit == '') {
  546. return json_show(1004, "商品单位不能为空");
  547. }
  548. $good_type = isset($this->post['good_type']) && $this->post['good_type'] !== "" ? intval($this->post['good_type']) : "";
  549. if ($good_type === '') {
  550. return json_show(1004, "参数good_type不能为空");
  551. }
  552. $moq = 0;
  553. $customized = 0;
  554. if ($good_type == 1) {
  555. $moq = isset($this->post['moq']) && $this->post['moq'] !== "" ? intval($this->post['moq']) : "";
  556. if ($moq === '') {
  557. return json_show(1004, "定制商品起订量不能为空");
  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. }
  564. $is_exclusive = isset($this->post['is_exclusive']) && $this->post['is_exclusive'] !== "" ? intval($this->post['is_exclusive']) : "";
  565. if ($is_exclusive === '') {
  566. return json_show(1004, "参数is_exclusive不能为空");
  567. }
  568. // $customized = isset($this->post['customized'])&&$this->post['customized']!==""? intval($this->post['customized']):"";
  569. // if($customized===''){
  570. // return json_show(1004,"参数customized不能为空");
  571. // }
  572. $tax = isset($this->post['tax']) && $this->post['tax'] !== "" ? intval($this->post['tax']) : "";
  573. if ($tax === '') {
  574. return json_show(1004, "参数tax不能为空");
  575. }
  576. $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] != "" ? trim($this->post['supplierNo']) : "";
  577. if ($supplierNo == '') {
  578. return json_show(1004, "参数supplierNo不能为空");
  579. }
  580. $good_size = isset($this->post['good_size']) && $this->post['good_size'] != "" ? trim($this->post['good_size']) : "";
  581. if ($good_size == '') {
  582. return json_show(1004, "参数good_size不能为空");
  583. }
  584. $company_id = isset($this->post['company_id']) && $this->post['company_id'] != "" ? trim($this->post['company_id']) : "";
  585. if ($company_id == '') {
  586. return json_show(1004, "参数company_id不能为空");
  587. }
  588. $is_auth = isset($this->post['is_auth']) && $this->post['is_auth'] !== "" ? intval($this->post['is_auth']) : "";
  589. if ($is_auth === '') {
  590. return json_show(1004, "参数is_auth不能为空");
  591. }
  592. $auth_img = isset($this->post['auth_img']) && $this->post['auth_img'] != "" ? trim($this->post['auth_img']) : "";
  593. // if($auth_img==''){
  594. // return json_show(1004,"商品不能为空");
  595. // }
  596. $after_sales = isset($this->post['after_sales']) && $this->post['after_sales'] != "" ? trim($this->post['after_sales']) : "";
  597. if ($after_sales == "") {
  598. return json_show(1004, "参数after_sales不能为空");
  599. }
  600. $craft_desc = isset($this->post['craft_desc']) && $this->post['craft_desc'] != "" ? trim($this->post['craft_desc']) : "";
  601. $good_remark = isset($this->post['good_remark']) && $this->post['good_remark'] != "" ? trim($this->post['good_remark']) : "";
  602. if ($good_remark === "") {
  603. return json_show(1004, "参数good_remark不能为空");
  604. }
  605. $weight = isset($this->post['weight']) && $this->post['weight'] !== "" ? floatval($this->post['weight']) : "";
  606. if ($weight === "") {
  607. return json_show(1004, "参数weight不能为空");
  608. }
  609. $packing_way = isset($this->post['packing_way']) && $this->post['packing_way'] !== "" ? trim($this->post['packing_way']) : "";
  610. if ($packing_way === "") {
  611. return json_show(1004, "参数packing_way不能为空");
  612. }
  613. $packing_size = isset($this->post['packing_size']) && $this->post['packing_size'] !== "" ? trim($this->post['packing_size']) : "";
  614. if ($packing_size === "") {
  615. return json_show(1004, "参数packing_size不能为空");
  616. }
  617. $packing_spec = isset($this->post['packing_spec']) && $this->post['packing_spec'] !== "" ? trim($this->post['packing_spec']) : "";
  618. if ($packing_spec === "") {
  619. return json_show(1004, "参数packing_spec不能为空");
  620. }
  621. $packing_weight = isset($this->post['packing_weight']) && $this->post['packing_weight'] !== "" ? floatval($this->post['packing_weight']) : "";
  622. if ($packing_weight === "") {
  623. return json_show(1004, "参数packing_weight不能为空");
  624. }
  625. $packing_list = isset($this->post['packing_list']) && $this->post['packing_list'] !== "" ? trim($this->post['packing_list']) : "";
  626. if ($packing_list === "") {
  627. return json_show(1004, "参数packing_list不能为空");
  628. }
  629. $good_bar = isset($this->post['good_bar']) && $this->post['good_bar'] !== "" ? trim($this->post['good_bar']) : "";
  630. $supply_area = isset($this->post['supply_area']) && $this->post['supply_area'] !== "" ? intval($this->post['supply_area']) : "";
  631. if ($supply_area === "") {
  632. return json_show(1004, "参数supply_area不能为空");
  633. }
  634. $delivery_place = isset($this->post['delivery_place']) && $this->post['delivery_place'] !== "" ? $this->post['delivery_place'] : "";
  635. if ($delivery_place === "") {
  636. return json_show(1004, "参数delivery_place不能为空");
  637. }
  638. $origin_place = isset($this->post['origin_place']) && $this->post['origin_place'] !== "" ? $this->post['origin_place'] : "";
  639. if ($origin_place === "") {
  640. return json_show(1004, "参数origin_place不能为空");
  641. }
  642. $delivery_day = isset($this->post['delivery_day']) && $this->post['delivery_day'] !== "" ? intval($this->post['delivery_day']) : "";
  643. if ($delivery_day === "") {
  644. return json_show(1004, "参数delivery_day不能为空");
  645. }
  646. $lead_time = isset($this->post['lead_time']) && $this->post['lead_time'] !== "" ? intval($this->post['lead_time']) : "0";
  647. // if($lead_time===""){
  648. // return json_show(1004,"参数lead_time不能为空");
  649. // }
  650. $sample_day = isset($this->post['sample_day']) && $this->post['sample_day'] !== "" ? intval($this->post['sample_day']) : "0";
  651. // if($sample_day===""){
  652. // return json_show(1004,"参数sample_day不能为空");
  653. // }
  654. // $sample_fee = isset($this->post['sample_fee'])&&$this->post['sample_fee']!==""? floatval
  655. //($this->post['sample_fee']):"0";
  656. $config = isset($this->post['config']) && $this->post['config'] !== "" ? trim($this->post['config']) : "";
  657. $other_config = isset($this->post['other_config']) && $this->post['other_config'] !== "" ? trim($this->post['other_config']) : "";
  658. $is_diff = isset($this->post['is_diff']) && $this->post['is_diff'] !== "" ? intval($this->post['is_diff']) : "0";
  659. $is_stock = isset($this->post['is_stock']) && $this->post['is_stock'] !== "" ? intval($this->post['is_stock']) : "0";
  660. $stock_moq = isset($this->post['stock_moq']) && $this->post['stock_moq'] !== "" ? intval($this->post['stock_moq']) : "0";
  661. if ($is_stock == 1 && $stock_moq == 0) {
  662. return json_show(1004, "库存品备库起订量不能为零");
  663. }
  664. $good_img = isset($this->post['good_img']) && $this->post['good_img'] != "" ? trim($this->post['good_img']) : "";
  665. if ($good_img === "") {
  666. return json_show(1004, "参数good_img不能为空");
  667. }
  668. $good_thumb_img = isset($this->post['good_thumb_img']) && $this->post['good_thumb_img'] !== "" ? trim($this->post['good_thumb_img']) : "";
  669. if ($good_thumb_img === "") {
  670. return json_show(1004, "参数good_thumb_img不能为空");
  671. }
  672. $good_info_img = isset($this->post['good_info_img']) && !empty($this->post['good_info_img']) ? trim($this->post['good_info_img']) : "";
  673. if ($good_info_img === "") {
  674. return json_show(1004, "参数good_info_img不能为空");
  675. }
  676. $count = Db::name("good_nake")->where(["spuCode" => $supcode, "is_del" => 0])->count();
  677. $speclist = isset($this->post['speclist']) && !empty($this->post['speclist']) ? $this->post['speclist'] : "";
  678. $uid = $this->request->user['uid'];
  679. $nickname = $this->request->user['nickname'];
  680. Db::startTrans();
  681. try {
  682. $temp = [
  683. "good_name" => $good_name,
  684. "cat_id" => $cat_id,
  685. 'brand_id' => $brandid,
  686. "good_unit" => $unit,
  687. "good_type" => $good_type,
  688. "companyNo" => $company_id,
  689. "moq" => $moq,
  690. "is_exclusive" => $is_exclusive,
  691. "customized" => $customized,
  692. "tax" => $tax,
  693. "supplierNo" => $supplierNo,
  694. "is_auth" => $is_auth,
  695. "good_size" => $good_size,
  696. "auth_img" => $auth_img,
  697. "after_sales" => $after_sales,
  698. "craft_desc" => $craft_desc,
  699. "good_remark" => $good_remark,
  700. "weight" => $weight,
  701. "packing_way" => $packing_way,
  702. "packing_size" => $packing_size,
  703. "packing_spec" => $packing_spec,
  704. "packing_list" => $packing_list,
  705. "packing_weight" => $packing_weight,
  706. "good_bar" => $good_bar,
  707. "supply_area" => $supply_area,
  708. "delivery_place" => $delivery_place,
  709. "origin_place" => $origin_place,
  710. "delivery_day" => $delivery_day,
  711. "lead_time" => $lead_time,
  712. "sample_day" => $sample_day,
  713. "is_diff" => $is_diff,
  714. 'is_stock' => $is_stock,
  715. "config" => $config,
  716. "other_config" => $other_config,
  717. "good_img" => $good_img,
  718. "stock_moq" => $stock_moq,
  719. "good_thumb_img" => $good_thumb_img,
  720. "good_info_img" => $good_info_img,
  721. "status" => $count > 0 ? 2 : 1,
  722. "updatetime" => date("Y-m-d H:i:s")
  723. ];
  724. $field = array_diff_assoc($temp, $data);
  725. $temp['field_change'] = empty($field) ? "" : json_encode(array_keys($field));
  726. $up = Db::name("good_basic")->where(["spuCode" => $supcode, "is_del" => 0])->save($temp);
  727. $timp = array_diff($temp, $data);
  728. $json = json_encode($timp, JSON_UNESCAPED_UNICODE);
  729. $jsp = json_encode($data, JSON_UNESCAPED_UNICODE);
  730. if ($up) {
  731. ChangeLog::logAdd(3, $data['spuCode'], $jsp, $json, ['id' => $uid, 'nickname' => $nickname], $this->post);
  732. if ($speclist !== "" && !empty($speclist)) {
  733. foreach ($speclist as $value) {
  734. $lemp = [];
  735. isset($value["id"]) && $value["id"] != '' ? $lemp['id'] = $value['id'] : "";
  736. $lemp['spuCode'] = $supcode;
  737. $lemp['spec_id'] = $value['spec_id'];
  738. $lemp['spec_value_id'] = $value['spec_value_id'];
  739. $lemp['is_del'] = isset($value['is_del']) ? $value['is_del'] : 0;
  740. isset($value["id"]) && $value["id"] != '' ? "" : $lemp['addtime'] = date("Y-m-d H:i:s");
  741. $lemp['updatetime'] = date("Y-m-d H:i:s");
  742. $count = Db::name("good_spec")->save($lemp);
  743. if ($count == false) {
  744. Db::rollback();
  745. return json_show(1004, "商品规格值修改失败");
  746. }
  747. }
  748. }
  749. //修改状态,添加待办
  750. ActionLog::logAdd(['id' => $uid, 'nickname' => $nickname], [
  751. "order_code" => $supcode,//咨询单详情编号
  752. "status" => $data['status'],//这里的status是之前的值
  753. "action_remark" => '',//备注
  754. "action_type" => "edit"//新建create,编辑edit,更改状态status
  755. ], "SPCB", $temp['status'], $data);
  756. ProcessOrder::AddProcess(['id' => $uid, 'nickname' => $nickname], [
  757. "order_type" => 'SPCB',
  758. "order_code" => $supcode,//咨询单详情编号
  759. "order_id" => $data['id'],
  760. "order_status" => $temp['status'],
  761. "before_status" => $data['status'],
  762. 'holder_id' => $data['createrid'],
  763. 'person_id' => Db::name('supplier')->where(['code' => $this->request->user['supplierNo'], 'is_del' => 0])->value('personid'),
  764. ]);
  765. Db::commit();
  766. return json_show(0, "更新成功");
  767. } else {
  768. Db::rollback();
  769. return json_show(1005, "更新失败");
  770. }
  771. } catch (\Exception $e) {
  772. Db::rollback();
  773. return json_show(1004, $e->getMessage());
  774. }
  775. }
  776. //修改商品价格信息
  777. public function updateGoodPriceInfo()
  778. {
  779. $this->post = $this->request->filter('trim')->post();
  780. $supcode = isset($this->post['spuCode']) && $this->post['spuCode'] != "" ? trim($this->post['spuCode']) : "";
  781. if ($supcode == "") {
  782. return json_show(1004, "参数spuCode不能为空");
  783. }
  784. $datas = Db::name("good_basic")->where(["spuCode" => $supcode, "is_del" => 0])->find();
  785. if ($datas == false) {
  786. return json_show(1004, "未找到商品数据");
  787. }
  788. $is_down = Db::name("good_platform")
  789. ->where(["spuCode" => $supcode, "is_del" => 0])
  790. ->where("exam_status", "<>", 8)
  791. ->find();
  792. if ($is_down != false) {
  793. return json_show(1004, "存在未下线商品数据");
  794. }
  795. $cert_fee = isset($this->post['cert_fee']) && $this->post['cert_fee'] !== "" ? floatval($this->post['cert_fee']) : "0";
  796. $packing_fee = isset($this->post['packing_fee']) && $this->post['packing_fee'] !== "" ? floatval($this->post['packing_fee']) : "0";
  797. $cost_fee = isset($this->post['cost_fee']) && $this->post['cost_fee'] !== "" ? floatval($this->post['cost_fee']) : "0";
  798. $mark_fee = isset($this->post['mark_fee']) && $this->post['mark_fee'] !== "" ? floatval($this->post['mark_fee']) : "0";
  799. $demo_fee = isset($this->post['demo_fee']) && $this->post['demo_fee'] !== "" ? floatval($this->post['demo_fee']) : "0";
  800. $open_fee = isset($this->post['open_fee']) && $this->post['open_fee'] !== "" ? floatval($this->post['open_fee']) : "0";
  801. $sample_fee = isset($this->post['sample_fee']) && $this->post['sample_fee'] !== "" ? floatval($this->post['sample_fee']) : "0";
  802. $noble_metal = isset($this->post['noble_metal']) && $this->post['noble_metal'] !== "" ? intval($this->post['noble_metal']) : "0";
  803. $noble_weight = isset($this->post['noble_weight']) && $this->post['noble_weight'] !== "" ? floatval($this->post['noble_weight']) : "0";
  804. $is_gold_price = isset($this->post['is_gold_price']) && $this->post['is_gold_price'] !== "" ? intval($this->post['is_gold_price']) : "0";
  805. $market_price = isset($this->post['market_price']) && $this->post['market_price'] !== "" ? floatval($this->post['market_price']) : "";
  806. $cgd_gold_price = isset($this->post['cgd_gold_price']) && $this->post['cgd_gold_price'] !== "" ? floatval($this->post['cgd_gold_price']) : "0";
  807. if ($market_price === "") {
  808. return json_show(1004, "参数market_price不能为空");
  809. }
  810. $nake_price = isset($this->post['nake_price']) && $this->post['nake_price'] !== "" ? floatval($this->post['nake_price']) : "";
  811. // $is_step = isset($this->post['is_step'])&&$this->post['is_step']!==""? intval($this->post['is_step']):"";
  812. // if($is_step===""){
  813. // return json_show(1004,"参数is_step不能为空");
  814. // }
  815. $good_ladder = isset($this->post['good_ladder']) && !empty($this->post['good_ladder']) ? $this->post['good_ladder'] : "";
  816. // if($is_step==1 && $good_ladder==""){
  817. // return json_show(1004,"启用阶梯,阶梯价不能为空");
  818. // }
  819. $data = [
  820. "cert_fee" => $cert_fee,
  821. "packing_fee" => $packing_fee,
  822. "cost_fee" => $cost_fee,
  823. "mark_fee" => $mark_fee,
  824. "demo_fee" => $demo_fee,
  825. "open_fee" => $open_fee,
  826. "sample_fee" => $sample_fee,
  827. "noble_metal" => $noble_metal,
  828. "noble_weight" => $noble_weight,
  829. "is_gold_price" => $is_gold_price,
  830. "market_price" => $market_price,
  831. "nake_price" => $nake_price,
  832. "cgd_gold_price" => $cgd_gold_price,
  833. "is_step" => count($good_ladder) > 1 ? 1 : 0,
  834. "status" => "3",
  835. "updatetime" => date("Y-m-d H:i:s")
  836. ];
  837. $field = array_diff_assoc($data, $datas);
  838. $data['field_change'] = empty($field) ? "" : json_encode(array_keys($field));
  839. $uid = $this->request->user['uid'];
  840. $nickname = $this->request->user['nickname'];
  841. Db::startTrans();
  842. try {
  843. $up = Db::name("good_basic")->where(["spuCode" => $supcode, "is_del" => 0])->save($data);
  844. $temp = array_diff($data, $datas);
  845. $json = json_encode($temp, JSON_UNESCAPED_UNICODE);
  846. $jsp = json_encode($datas, JSON_UNESCAPED_UNICODE);
  847. if ($up) {
  848. ChangeLog::logAdd(3, $datas['spuCode'], $jsp, $json, ['id' => $uid, 'nickname' => $nickname], $this->post);
  849. //修改状态,添加待办
  850. ActionLog::logAdd(['id' => $uid, 'nickname' => $nickname], [
  851. "order_code" => $supcode,//咨询单详情编号
  852. "status" => $datas['status'],//这里的status是之前的值
  853. "action_remark" => '',//备注
  854. "action_type" => "edit"//新建create,编辑edit,更改状态status
  855. ], "SPCB", $data['status'], $data);
  856. ProcessOrder::AddProcess(['id' => $uid, 'nickname' => $nickname], [
  857. "order_type" => 'SPCB',
  858. "order_code" => $supcode,//咨询单详情编号
  859. "order_id" => $datas['id'],
  860. "order_status" => $data['status'],
  861. "before_status" => $datas['status'],
  862. 'holder_id' => $datas['createrid'],
  863. 'person_id' => Db::name('supplier')->where(['code' => $this->request->user['supplierNo'], 'is_del' => 0])->value('personid'),
  864. ]);
  865. // $online = Db::name("good_platform")->where(["spuCode"=>$supcode,"is_del"=>0])->find();
  866. // if($online){
  867. // $onup = Db::name("good_platform")->where(["spuCode"=>$supcode,"is_del"=>0])->save
  868. // (["exam_status"=>2,"updatetime"=>date("Y-m-d H:i:s")]);
  869. // if($onup==false){
  870. // Db::rollback();
  871. // return json_show(1004,"商品规成本修改失败");
  872. // }
  873. // //修改状态,添加待办
  874. // ActionLog::logAdd(['id'=>$uid,'nickname'=>$nickname], [
  875. // "order_code" =>$online['skuCode'],//咨询单详情编号
  876. // "status" => $online['exam_status'],//这里的status是之前的值
  877. // "action_remark" => '',//备注
  878. // "action_type" => "edit"//新建create,编辑edit,更改状态status
  879. // ], "SPSX",2,["exam_status"=>2,"updatetime"=>date("Y-m-d H:i:s")]);
  880. //
  881. // ProcessOrder::AddProcess(['id'=>$uid,'nickname'=>$nickname], [
  882. // "order_type" => 'SPSX',
  883. // "order_code" => $online['skuCode'],//咨询单详情编号
  884. // "order_id" => $online['id'],
  885. // "order_status" =>2,"before_status"=>$online['exam_status']
  886. // ]);
  887. // }
  888. if ($good_ladder !== "" && !empty($good_ladder)) {
  889. // $user =GetUserInfo($this->post['token']);
  890. foreach ($good_ladder as $value) {
  891. $lemp = [];
  892. isset($value["id"]) && $value["id"] != '' ? $lemp['id'] = $value['id'] : "";
  893. $lemp['spuCode'] = $supcode;
  894. $lemp['min_num'] = $value['min_num'];
  895. $lemp['nake_fee'] = $value['nake_fee'];
  896. $lemp['cost_fee'] = $value['cost_fee'];
  897. $lemp['delivery_fee'] = $value['delivery_fee'];
  898. $lemp['cert_fee'] = $value['cert_fee'];
  899. $lemp['mark_fee'] = $value['mark_fee'];
  900. $lemp['package_fee'] = $value['package_fee'];
  901. $lemp['other_fee'] = $value['other_fee'];
  902. $top_cat_id = made($datas['cat_id']);//获取所有分类
  903. $top_cat_id = isset($top_cat_id[0]['id']) ? $top_cat_id[0]['id'] : 0;//获取顶级分类id
  904. if ($is_gold_price == 1 && $top_cat_id == 6) {
  905. //$gold =Db::name("gold_price1")->where(["type"=>$noble_metal,"status"=>1,"is_del"=>0])
  906. // ->order("addtime desc")->find();
  907. //$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'];
  908. //成本合计=贵金属重量*供应商采购金价 + 工艺费*贵金属重量+加标费+包装费+证书费+成本裸价+运费+其他费用
  909. //成本总计启用实时金价时,采用供应商实时金价
  910. $lemp['nake_total'] = $noble_weight * $cgd_gold_price + $value['cost_fee'] * $noble_weight +
  911. $value['mark_fee'] + $value['package_fee'] + $value['cert_fee'] + $value['nake_fee'] + $value['delivery_fee'] + $value['other_fee'];
  912. } else {
  913. $lemp['nake_total'] = $value['nake_fee'] + $value['delivery_fee'] + $value['cert_fee'] + $value['mark_fee'] + $value['package_fee'] + $value['other_fee'];
  914. }
  915. $lemp['is_del'] = isset($value['is_del']) ? $value['is_del'] : 0;
  916. $lemp['creater_id'] = $uid;
  917. $lemp['creater'] = $nickname;
  918. isset($value["id"]) && $value["id"] != '' ? "" : $lemp['addtime'] = date("Y-m-d H:i:s");
  919. $lemp['updatetime'] = date("Y-m-d H:i:s");
  920. $count = Db::name("good_nake")->save($lemp);
  921. if ($count == false) {
  922. Db::rollback();
  923. return json_show(1004, "商品规成本修改失败");
  924. }
  925. }
  926. }
  927. Db::commit();
  928. return json_show(0, "更新成功");
  929. } else {
  930. Db::rollback();
  931. return json_show(1005, "更新失败");
  932. }
  933. } catch (\Exception $e) {
  934. Db::rollback();
  935. return json_show(1005, $e->getMessage());
  936. }
  937. }
  938. //修改商品成本全部信息
  939. public function editGoodUp()
  940. {
  941. $this->post = $this->request->filter('trim')->post();
  942. $supcode = isset($this->post['spuCode']) && $this->post['spuCode'] != "" ? trim($this->post['spuCode']) : "";
  943. if ($supcode == "") {
  944. return json_show(1004, "参数spuCode不能为空");
  945. }
  946. $data = Db::name("good_basic")->where(["spuCode" => $supcode, "is_del" => 0])->find();
  947. if ($data == false) {
  948. return json_show(1004, "未找到商品数据");
  949. }
  950. $is_down = Db::name("good_platform")
  951. ->where(["spuCode" => $supcode, "is_del" => 0])
  952. ->where("exam_status", "not in", [1, 8])//exam_status=1待完善成本,8已下线,除了这两个状态外其他状态都不允许编辑
  953. ->find();
  954. if ($is_down != false) {
  955. return json_show(1004, "存在未下线商品数据");
  956. }
  957. if ($data['status'] != 6 && $data['status'] != 7 && $data['status'] != 8) {
  958. return json_show(1004, "商品状态有误");
  959. }
  960. $good_name = isset($this->post['good_name']) && $this->post['good_name'] != "" ? trim($this->post['good_name']) : "";
  961. if ($good_name == "") {
  962. return json_show(1004, "商品名称不能为空");
  963. }
  964. $cat_id = isset($this->post['cat_id']) && $this->post['cat_id'] != "" ? intval($this->post['cat_id']) : "";
  965. if ($cat_id == '') {
  966. return json_show(1004, "商品分类不能为空");
  967. }
  968. $brandid = isset($this->post['brandid']) && $this->post['brandid'] != "" ? intval($this->post['brandid']) : "0";
  969. // if($brandid==''){
  970. // return json_show(1004,"商品品牌不能为空");
  971. // }
  972. $unit = isset($this->post['unit']) && $this->post['unit'] != "" ? trim($this->post['unit']) : "";
  973. if ($unit == '') {
  974. return json_show(1004, "商品单位不能为空");
  975. }
  976. $good_type = isset($this->post['good_type']) && $this->post['good_type'] !== "" ? intval($this->post['good_type']) : "";
  977. if ($good_type === '') {
  978. return json_show(1004, "参数good_type不能为空");
  979. }
  980. $moq = 0;
  981. $customized = 0;
  982. if ($good_type == 1) {
  983. $moq = isset($this->post['moq']) && $this->post['moq'] !== "" ? intval($this->post['moq']) : "";
  984. if ($moq === '') {
  985. return json_show(1004, "定制商品起订量不能为空");
  986. }
  987. $customized = isset($this->post['customized']) && $this->post['customized'] !== "" ? intval($this->post['customized']) : "";
  988. if ($customized === '') {
  989. return json_show(1004, "参数customized不能为空");
  990. }
  991. }
  992. $is_exclusive = isset($this->post['is_exclusive']) && $this->post['is_exclusive'] !== "" ? intval($this->post['is_exclusive']) : "";
  993. if ($is_exclusive === '') {
  994. return json_show(1004, "参数is_exclusive不能为空");
  995. }
  996. // $customized = isset($this->post['customized'])&&$this->post['customized']!==""? intval($this->post['customized']):"";
  997. // if($customized===''){
  998. // return json_show(1004,"参数customized不能为空");
  999. // }
  1000. $tax = isset($this->post['tax']) && $this->post['tax'] !== "" ? intval($this->post['tax']) : "";
  1001. if ($tax === '') {
  1002. return json_show(1004, "参数tax不能为空");
  1003. }
  1004. $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] != "" ? trim($this->post['supplierNo']) : "";
  1005. if ($supplierNo == '') {
  1006. return json_show(1004, "参数supplierNo不能为空");
  1007. }
  1008. $good_size = isset($this->post['good_size']) && $this->post['good_size'] != "" ? trim($this->post['good_size']) : "";
  1009. if ($good_size == '') {
  1010. return json_show(1004, "参数good_size不能为空");
  1011. }
  1012. $company_id = isset($this->post['companyNo']) && $this->post['companyNo'] != "" ? trim($this->post['companyNo']) : "";
  1013. if ($company_id == '') {
  1014. return json_show(1004, "参数companyNo不能为空");
  1015. }
  1016. $is_auth = isset($this->post['is_auth']) && $this->post['is_auth'] !== "" ? intval($this->post['is_auth']) : "";
  1017. if ($is_auth === '') {
  1018. return json_show(1004, "参数is_auth不能为空");
  1019. }
  1020. $auth_img = isset($this->post['auth_img']) && $this->post['auth_img'] != "" ? trim($this->post['auth_img']) : "";
  1021. // if($auth_img==''){
  1022. // return json_show(1004,"商品不能为空");
  1023. // }
  1024. $after_sales = isset($this->post['after_sales']) && $this->post['after_sales'] != "" ? trim($this->post['after_sales']) : "";
  1025. if ($after_sales == "") {
  1026. return json_show(1004, "参数after_sales不能为空");
  1027. }
  1028. $craft_desc = isset($this->post['craft_desc']) && $this->post['craft_desc'] != "" ? trim($this->post['craft_desc']) : "";
  1029. $good_remark = isset($this->post['good_remark']) && $this->post['good_remark'] != "" ? trim($this->post['good_remark']) : "";
  1030. if ($good_remark === "") {
  1031. return json_show(1004, "参数good_remark不能为空");
  1032. }
  1033. $weight = isset($this->post['weight']) && $this->post['weight'] !== "" ? floatval($this->post['weight']) : "";
  1034. if ($weight === "") {
  1035. return json_show(1004, "参数weight不能为空");
  1036. }
  1037. $packing_way = isset($this->post['packing_way']) && $this->post['packing_way'] !== "" ? trim($this->post['packing_way']) : "";
  1038. if ($packing_way === "") {
  1039. return json_show(1004, "参数packing_way不能为空");
  1040. }
  1041. $packing_size = isset($this->post['packing_size']) && $this->post['packing_size'] !== "" ? trim($this->post['packing_size']) : "";
  1042. if ($packing_size === "") {
  1043. return json_show(1004, "参数packing_size不能为空");
  1044. }
  1045. $packing_spec = isset($this->post['packing_spec']) && $this->post['packing_spec'] !== "" ? trim($this->post['packing_spec']) : "";
  1046. if ($packing_spec === "") {
  1047. return json_show(1004, "参数packing_spec不能为空");
  1048. }
  1049. $packing_weight = isset($this->post['packing_weight']) && $this->post['packing_weight'] !== "" ? floatval($this->post['packing_weight']) : "";
  1050. if ($packing_weight === "") {
  1051. return json_show(1004, "参数packing_weight不能为空");
  1052. }
  1053. $packing_list = isset($this->post['packing_list']) && $this->post['packing_list'] !== "" ? trim($this->post['packing_list']) : "";
  1054. if ($packing_list === "") {
  1055. return json_show(1004, "参数packing_list不能为空");
  1056. }
  1057. $good_bar = isset($this->post['good_bar']) && $this->post['good_bar'] !== "" ? trim($this->post['good_bar']) : "";
  1058. $supply_area = isset($this->post['supply_area']) && $this->post['supply_area'] !== "" ? intval($this->post['supply_area']) : "";
  1059. if ($supply_area === "") {
  1060. return json_show(1004, "参数supply_area不能为空");
  1061. }
  1062. $delivery_place = isset($this->post['delivery_place']) && $this->post['delivery_place'] !== "" ? $this->post['delivery_place'] : "";
  1063. if ($delivery_place === "") {
  1064. return json_show(1004, "参数delivery_place不能为空");
  1065. }
  1066. $origin_place = isset($this->post['origin_place']) && $this->post['origin_place'] !== "" ? $this->post['origin_place'] : "";
  1067. if ($origin_place === "") {
  1068. return json_show(1004, "参数origin_place不能为空");
  1069. }
  1070. $delivery_day = isset($this->post['delivery_day']) && $this->post['delivery_day'] !== "" ? intval($this->post['delivery_day']) : "";
  1071. if ($delivery_day === "") {
  1072. return json_show(1004, "参数delivery_day不能为空");
  1073. }
  1074. $lead_time = isset($this->post['lead_time']) && $this->post['lead_time'] !== "" ? intval($this->post['lead_time']) : "0";
  1075. // if($lead_time===""){
  1076. // return json_show(1004,"参数lead_time不能为空");
  1077. // }
  1078. $sample_day = isset($this->post['sample_day']) && $this->post['sample_day'] !== "" ? intval($this->post['sample_day']) : "0";
  1079. // if($sample_day===""){
  1080. // return json_show(1004,"参数sample_day不能为空");
  1081. // }
  1082. $sample_fee = isset($this->post['sample_fee']) && $this->post['sample_fee'] !== "" ? floatval($this->post['sample_fee']) : "0";
  1083. $good_img = isset($this->post['good_img']) && $this->post['good_img'] != "" ? trim($this->post['good_img']) : "";
  1084. if ($good_img === "") {
  1085. return json_show(1004, "参数good_img不能为空");
  1086. }
  1087. $good_thumb_img = isset($this->post['good_thumb_img']) && $this->post['good_thumb_img'] !== "" ? trim($this->post['good_thumb_img']) : "";
  1088. if ($good_thumb_img === "") {
  1089. return json_show(1004, "参数good_thumb_img不能为空");
  1090. }
  1091. $good_info_img = isset($this->post['good_info_img']) && !empty($this->post['good_info_img']) ? trim($this->post['good_info_img']) : "";
  1092. if ($good_info_img === "") {
  1093. return json_show(1004, "参数good_info_img不能为空");
  1094. }
  1095. $cert_fee = isset($this->post['cert_fee']) && $this->post['cert_fee'] !== "" ? floatval($this->post['cert_fee']) : "0";
  1096. $packing_fee = isset($this->post['packing_fee']) && $this->post['packing_fee'] !== "" ? floatval($this->post['packing_fee']) : "0";
  1097. $cost_fee = isset($this->post['cost_fee']) && $this->post['cost_fee'] !== "" ? floatval($this->post['cost_fee']) : "0";
  1098. $mark_fee = isset($this->post['mark_fee']) && $this->post['mark_fee'] !== "" ? floatval($this->post['mark_fee']) : "0";
  1099. $demo_fee = isset($this->post['demo_fee']) && $this->post['demo_fee'] !== "" ? floatval($this->post['demo_fee']) : "0";
  1100. $open_fee = isset($this->post['open_fee']) && $this->post['open_fee'] !== "" ? floatval($this->post['open_fee']) : "0";
  1101. $noble_metal = isset($this->post['noble_metal']) && $this->post['noble_metal'] !== "" ? intval($this->post['noble_metal']) : "0";
  1102. $noble_weight = isset($this->post['noble_weight']) && $this->post['noble_weight'] !== "" ? floatval($this->post['noble_weight']) : "0";
  1103. $is_gold_price = isset($this->post['is_gold_price']) && $this->post['is_gold_price'] !== "" ? intval($this->post['is_gold_price']) : "0";
  1104. $market_price = isset($this->post['market_price']) && $this->post['market_price'] !== "" ? floatval($this->post['market_price']) : "";
  1105. $cgd_gold_price = isset($this->post['cgd_gold_price']) && $this->post['cgd_gold_price'] !== "" ? floatval($this->post['cgd_gold_price']) : "0";
  1106. if ($market_price === "") {
  1107. return json_show(1004, "参数market_price不能为空");
  1108. }
  1109. $nake_price = isset($this->post['nake_price']) && $this->post['nake_price'] !== "" ? floatval($this->post['nake_price']) : "0";
  1110. $config = isset($this->post['config']) && $this->post['config'] !== "" ? trim($this->post['config']) : "";
  1111. $other_config = isset($this->post['other_config']) && $this->post['other_config'] !== "" ? trim($this->post['other_config']) : "";
  1112. $is_diff = isset($this->post['is_diff']) && $this->post['is_diff'] !== "" ? intval($this->post['is_diff']) : "0";
  1113. $is_stock = isset($this->post['is_stock']) && $this->post['is_stock'] !== "" ? intval($this->post['is_stock']) : "0";
  1114. $stock_moq = isset($this->post['stock_moq']) && $this->post['stock_moq'] !== "" ? intval($this->post['stock_moq']) : "0";
  1115. if ($is_stock == 1 && $stock_moq == 0) {
  1116. return json_show(1004, "库存品备库起订量不能为零");
  1117. }
  1118. // $is_step = isset($this->post['is_step'])&&$this->post['is_step']!==""? intval($this->post['is_step']):"";
  1119. // if($is_step===""){
  1120. // return json_show(1004,"参数is_step不能为空");
  1121. // }
  1122. $good_ladder = isset($this->post['good_ladder']) && !empty($this->post['good_ladder']) ? $this->post['good_ladder'] : "";
  1123. // if($is_step==1 && $good_ladder==""){
  1124. // return json_show(1004,"启用阶梯,阶梯价不能为空");
  1125. // }
  1126. $speclist = isset($this->post['speclist']) && !empty($this->post['speclist']) ? $this->post['speclist'] : "";
  1127. $is_support_barter = isset($this->post['is_support_barter']) && $this->post['is_support_barter'] !== "" ? intval($this->post['is_support_barter']) : 1;
  1128. $uid = $this->request->user['uid'];
  1129. $nickname = $this->request->user['nickname'];
  1130. Db::startTrans();
  1131. try {
  1132. $temp = [
  1133. "good_name" => $good_name,
  1134. "cat_id" => $cat_id,
  1135. 'brand_id' => $brandid,
  1136. "good_unit" => $unit,
  1137. "good_type" => $good_type,
  1138. "companyNo" => $company_id,
  1139. "moq" => $moq,
  1140. "is_exclusive" => $is_exclusive,
  1141. "customized" => $customized,
  1142. "tax" => $tax,
  1143. "supplierNo" => $supplierNo,
  1144. "is_auth" => $is_auth,
  1145. "good_size" => $good_size,
  1146. "auth_img" => $auth_img,
  1147. "after_sales" => $after_sales,
  1148. "craft_desc" => $craft_desc,
  1149. "good_remark" => $good_remark,
  1150. "weight" => $weight,
  1151. "packing_way" => $packing_way,
  1152. "packing_size" => $packing_size,
  1153. "packing_spec" => $packing_spec,
  1154. "packing_list" => $packing_list,
  1155. "packing_weight" => $packing_weight,
  1156. "good_bar" => $good_bar,
  1157. "supply_area" => $supply_area,
  1158. "delivery_place" => $delivery_place,
  1159. "origin_place" => $origin_place,
  1160. "delivery_day" => $delivery_day,
  1161. "lead_time" => $lead_time,
  1162. "sample_day" => $sample_day,
  1163. "sample_fee" => $sample_fee,
  1164. "good_img" => $good_img,
  1165. "good_thumb_img" => $good_thumb_img,
  1166. "good_info_img" => $good_info_img,
  1167. "cert_fee" => $cert_fee,
  1168. "packing_fee" => $packing_fee,
  1169. "is_diff" => $is_diff,
  1170. "config" => $config,
  1171. "other_config" => $other_config,
  1172. "is_stock" => $is_stock,
  1173. "cost_fee" => $cost_fee,
  1174. "mark_fee" => $mark_fee,
  1175. "demo_fee" => $demo_fee,
  1176. "open_fee" => $open_fee,
  1177. "noble_metal" => $noble_metal,
  1178. "noble_weight" => $noble_weight,
  1179. "is_gold_price" => $is_gold_price,
  1180. "market_price" => $market_price,
  1181. "nake_price" => $nake_price,
  1182. "cgd_gold_price" => $cgd_gold_price,
  1183. "is_step" => count($good_ladder) > 1 ? 1 : 0,
  1184. "stock_moq" => $stock_moq,
  1185. "status" => "0",
  1186. "updatetime" => date("Y-m-d H:i:s"),
  1187. 'is_support_barter' => $is_support_barter
  1188. ];
  1189. $field = array_diff_assoc($temp, $data);
  1190. $temp['field_change'] = empty($field) ? "" : json_encode(array_keys($field));
  1191. $up = Db::name("good_basic")->where(["spuCode" => $supcode, "is_del" => 0])->save($temp);
  1192. $var = array_diff($temp, $data);
  1193. $json = json_encode($var, JSON_UNESCAPED_UNICODE);
  1194. $dat = json_encode($data, JSON_UNESCAPED_UNICODE);
  1195. if ($up) {
  1196. ChangeLog::logAdd(3, $data['spuCode'], $dat, $json, ['id' => $uid, 'nickname' => $nickname], $this->post);
  1197. //修改状态,添加待办
  1198. ActionLog::logAdd(['id' => $uid, 'nickname' => $nickname], [
  1199. "order_code" => $supcode,//咨询单详情编号
  1200. "status" => $data['status'],//这里的status是之前的值
  1201. "action_remark" => '',//备注
  1202. "action_type" => "create"//新建create,编辑edit,更改状态status
  1203. ], "SPCB", 0, $temp);
  1204. ProcessOrder::AddProcess(['id' => $uid, 'nickname' => $nickname], [
  1205. "order_type" => 'SPCB',
  1206. "order_code" => $supcode,//咨询单详情编号
  1207. "order_id" => $data['id'],
  1208. "order_status" => 0,
  1209. "before_status" => 0,
  1210. 'holder_id' => $data['createrid'],
  1211. 'person_id' => Db::name('supplier')->where(['code' => $this->request->user['supplierNo'], 'is_del' => 0])->value('personid'),
  1212. ]);
  1213. if ($speclist !== "" && !empty($speclist)) {
  1214. foreach ($speclist as $value) {
  1215. $lemp = [];
  1216. isset($value["id"]) && $value["id"] != '' ? $lemp['id'] = $value['id'] : "";
  1217. $lemp['spuCode'] = $supcode;
  1218. $lemp['spec_id'] = $value['spec_id'];
  1219. $lemp['spec_value_id'] = $value['spec_value_id'];
  1220. $lemp['is_del'] = isset($value['is_del']) ? $value['is_del'] : 0;
  1221. isset($value["id"]) && $value["id"] != '' ? "" : $lemp['addtime'] = date("Y-m-d H:i:s");
  1222. $lemp['updatetime'] = date("Y-m-d H:i:s");
  1223. $count = Db::name("good_spec")->save($lemp);
  1224. if ($count == false) {
  1225. Db::rollback();
  1226. return json_show(1004, "商品规格值修改失败");
  1227. }
  1228. }
  1229. }
  1230. if ($good_ladder !== "" && !empty($good_ladder)) {
  1231. // $user =GetUserInfo($this->post['token']);//获取用户信息,下面更新成本表的创建人
  1232. $top_cat_id = made($cat_id);//获取所有分类
  1233. $top_cat_id = isset($top_cat_id[0]['id']) ? $top_cat_id[0]['id'] : 0;//获取顶级分类id
  1234. foreach ($good_ladder as $value) {
  1235. $lemp = [];
  1236. isset($value["id"]) && $value["id"] != '' ? $lemp['id'] = $value['id'] : "";
  1237. $lemp['spuCode'] = $supcode;
  1238. $lemp['min_num'] = $value['min_num'];
  1239. $lemp['nake_fee'] = $value['nake_fee'];
  1240. $lemp['cost_fee'] = $value['cost_fee'];
  1241. $lemp['delivery_fee'] = $value['delivery_fee'];
  1242. $lemp['cert_fee'] = $value['cert_fee'];
  1243. $lemp['mark_fee'] = $value['mark_fee'];
  1244. $lemp['package_fee'] = $value['package_fee'];
  1245. $lemp['other_fee'] = $value['other_fee'];
  1246. if ($is_gold_price == 1 && $top_cat_id == 6) {
  1247. // $gold =Db::name("gold_price1")->where(["type"=>$noble_metal,"status"=>1,"is_del"=>0])
  1248. // ->order("addtime desc")->find();
  1249. //$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'];
  1250. //成本合计=贵金属重量*供应商采购金价 + 工艺费*贵金属重量+加标费+包装费+证书费+成本裸价+运费+其他费用
  1251. //成本总计启用实时金价时,采用供应商实时金价
  1252. $lemp['nake_total'] = $noble_weight * $cgd_gold_price + $value['cost_fee'] * $noble_weight +
  1253. $value['mark_fee'] + $value['package_fee'] + $value['cert_fee'] + $value['nake_fee'] + $value['delivery_fee'] + $value['other_fee'];
  1254. } else {
  1255. $lemp['nake_total'] = $value['nake_fee'] + $value['delivery_fee'] + $value['cert_fee'] + $value['mark_fee'] + $value['package_fee'] + $value['other_fee'];
  1256. }
  1257. $lemp['creater_id'] = $this->request->user['uid'];
  1258. $lemp['creater'] = $this->request->user['nickname'];
  1259. $lemp['is_del'] = isset($value['is_del']) ? $value['is_del'] : 0;
  1260. isset($value["id"]) && $value["id"] != '' ? "" : $lemp['addtime'] = date("Y-m-d H:i:s");
  1261. $lemp['updatetime'] = date("Y-m-d H:i:s");
  1262. $count = Db::name("good_nake")->save($lemp);
  1263. if ($count == false) {
  1264. Db::rollback();
  1265. return json_show(1004, "商品规成本修改失败");
  1266. }
  1267. }
  1268. }
  1269. Db::commit();
  1270. return json_show(0, "更新成功");
  1271. } else {
  1272. Db::rollback();
  1273. return json_show(1005, "更新失败");
  1274. }
  1275. } catch (\Exception $e) {
  1276. Db::rollback();
  1277. return json_show(1004, $e->getMessage());
  1278. }
  1279. }
  1280. //获取商品详情
  1281. public function read()
  1282. {
  1283. $this->post = $this->request->filter('trim')->post();
  1284. $supcode = isset($this->post['spuCode']) && $this->post['spuCode'] != "" ? trim($this->post['spuCode']) : "";
  1285. if ($supcode == "") {
  1286. return json_show(1004, "参数spuCode不能为空");
  1287. }
  1288. $data = Db::name("good_basic")->where(["spuCode" => $supcode, "is_del" => 0])->find();
  1289. if ($data == false) {
  1290. return json_show(1004, "未找到商品数据");
  1291. }
  1292. $unit = Db::name("unit")->where(["id" => $data['good_unit']])->find();
  1293. $data['unit'] = isset($unit['unit']) ? $unit['unit'] : '';
  1294. $data['cat_info'] = made($data['cat_id'], []);
  1295. $spec = Db::name("good_spec")->where(["spuCode" => $supcode, "is_del" => 0])->select()->toArray();
  1296. $supplier = Db::name("supplier")->where(["code" => $data['supplierNo']])->find();
  1297. $data['supplierName'] = isset($supplier['name']) ? $supplier['name'] : "";
  1298. $supplier = Db::name("supplier")->where(["code" => $data['supplierNo']])->find();
  1299. $data['supplierName'] = isset($supplier['name']) ? $supplier['name'] : "";
  1300. $company = Db::name("business")->where(["companyNo" => $data['companyNo']])->find();
  1301. $data['company'] = isset($company['company']) ? $company['company'] : "";
  1302. $data['field_change'] = $data['field_change'] != '' ? json_decode($data['field_change']) : "";
  1303. if ($data['brand_id'] != 0) {
  1304. $brand = Db::name("brand")->where(["id" => $data['brand_id']])->find();
  1305. $data["brand_name"] = isset($brand['brand_name']) ? $brand['brand_name'] : "";
  1306. } else {
  1307. $data["brand_name"] = "";
  1308. $data["brand_id"] = "";
  1309. }
  1310. $excluse = makeExcluse($data['is_exclusive']);
  1311. $data['exclusive'] = $excluse;
  1312. $data['noble_name'] = isset($data['noble_metal']) && $data['noble_metal'] != 0 ? $this->noble[$data['noble_metal']] : "";
  1313. $data["good_info_img"] = $data['good_info_img'] != "" ? $data['good_info_img'] : '';
  1314. $data["good_img"] = $data['good_img'] != "" ? $data['good_img'] : [];
  1315. $gold = [];
  1316. if ($data['is_gold_price'] == 1) {
  1317. $gold = Db::name("gold_price1")->where(["type" => $data['noble_metal'], "status" => 1, "is_del" => 0])->order("addtime desc")->find();
  1318. }
  1319. $data['gold_price'] = isset($gold["price"]) ? $gold["price"] : 0;
  1320. $speclist = [];
  1321. if (!empty($spec)) {
  1322. foreach ($spec as $value) {
  1323. $temp = [];
  1324. $temp['id'] = $value['id'];
  1325. $temp['spuCode'] = $value['spuCode'];
  1326. $temp['spec_id'] = $value['spec_id'];
  1327. $temp['spec_value_id'] = $value['spec_value_id'];
  1328. $temp['is_del'] = $value['is_del'];
  1329. $sp = Db::name("specs")->where(["id" => $value['spec_id']])->find();
  1330. $temp['spec_name'] = isset($sp["spec_name"]) ? $sp["spec_name"] : "";
  1331. $spv = Db::name("spec_value")->where(["id" => $value['spec_value_id']])->find();
  1332. $temp['spec_value'] = isset($spv["spec_value"]) ? $spv["spec_value"] : "";
  1333. $speclist[] = $temp;
  1334. }
  1335. }
  1336. $data["speclist"] = empty($speclist) ? [] : $speclist;
  1337. // $nake=[];
  1338. $nakelist = Db::name("good_nake")->where(['spuCode' => $supcode, "is_del" => 0])->select()->toArray();
  1339. // $catinfo = Db::name("cat")->where(["id"=>$data['cat_id']])->find();
  1340. // $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  1341. $nakearry = [];
  1342. if (!empty($nakelist)) {
  1343. foreach ($nakelist as $value) {
  1344. $nakearry[] = $value;
  1345. }
  1346. }
  1347. $data["nakelist"] = $nakearry;
  1348. return json_show(0, "获取成功", $data);
  1349. }
  1350. //创建规格值
  1351. public function createSpec()
  1352. {
  1353. $this->post = $this->request->filter('trim')->post();
  1354. $spec_id = isset($this->post['spec_id']) && $this->post['spec_id'] !== "" ? intval($this->post['spec_id']) : "";
  1355. if ($spec_id == "") {
  1356. return json_show(1002, "参数spec_id不能为空");
  1357. }
  1358. $spec_value = isset($this->post['spec_value']) && $this->post['spec_value'] !== "" ? trim($this->post['spec_value']) : "";
  1359. if ($spec_value == "") {
  1360. return json_show(1002, "参数spec_value不能为空");
  1361. }
  1362. $id_is_empty = Db::name('spec_value')
  1363. ->field('id')
  1364. ->where([
  1365. 'spec_id' => $spec_id,
  1366. 'spec_value' => $spec_value,
  1367. 'is_del' => 0
  1368. ])->find();
  1369. if ($id_is_empty) return json_show(1005, '数据库已存在该规格值');
  1370. else {
  1371. $data = [
  1372. "spec_id" => $spec_id,
  1373. "spec_value" => $spec_value,
  1374. "is_del" => 0,
  1375. "addtime" => date("Y-m-d H:i:s"),
  1376. "updatetime" => date("Y-m-d H:i:s")
  1377. ];
  1378. $info = Db::name("spec_value")->insert($data);
  1379. if ($info) return json_show(0, "新建成功");
  1380. else return json_show(1002, "新建失败");
  1381. }
  1382. }
  1383. //所有规格值
  1384. public function allSpec()
  1385. {
  1386. $spec_id = $this->request->filter('trim')->post('spec_id/d', 0);
  1387. if ($spec_id == 0) {
  1388. return json_show(1002, "参数spec_id不能为空");
  1389. }
  1390. $info = Db::name('spec_value')
  1391. ->where(['spec_id' => $spec_id, 'is_del' => 0])
  1392. ->select()
  1393. ->toArray();
  1394. return json_show(0, "获取成功", $info);
  1395. }
  1396. //分类信息
  1397. public function catInfo()
  1398. {
  1399. // $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
  1400. $id = $this->request->filter('trim')->post('id/d', 0);
  1401. if ($id == "") {
  1402. return json_show(1002, "参数id不能为空");
  1403. }
  1404. $idinfo = Db::name('cat')->where(['id' => $id])->find();
  1405. if ($idinfo == "") {
  1406. return json_show(1002, "未找到数据");
  1407. }
  1408. $info = Db::name('cat_specs')->where(['cat_id' => $idinfo['id'], 'is_del' => 0])->column('specs_id');
  1409. $temp = Db::name('specs')->where(['id' => $info, 'is_del' => 0])->field("id,spec_name")->select();
  1410. //$idinfo['cat_id']=$info['cat_id'];
  1411. $idinfo['spec'] = $temp;
  1412. // $idinfo['specs_id']=$info;
  1413. return json_show(0, "获取成功", $idinfo);
  1414. }
  1415. //实时金价列表
  1416. public function goldPriceLastList()
  1417. {
  1418. $this->post = $this->request->filter('trim')->post();
  1419. $where = [['g.is_del', '=', 0]];
  1420. $type = isset($this->post['type']) && $this->post['type'] != "" ? intval($this->post['type']) : "";
  1421. if ($type !== "") $where[] = ['g.type', '=', $type];
  1422. $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  1423. if ($company_name !== "") $where[] = ["g.action_id", 'in', get_company_item_user_by_name($company_name)];
  1424. $ids = Db::name("gold_price1")
  1425. ->where(['is_del' => 0])
  1426. ->group("type")
  1427. ->column("max(id) as id");
  1428. $where[] = ['g.id', 'in', $ids];
  1429. $list = Db::name("gold_price1")
  1430. ->alias('g')
  1431. ->field('g.*,u.itemid')
  1432. ->leftJoin("depart_user u", "u.uid=g.action_id AND u.is_del=0")
  1433. ->where($where)
  1434. ->cursor();
  1435. $data = [];
  1436. foreach ($list as $value) {
  1437. $value['type_cn'] = $this->gold[$value['type']];
  1438. $value['company_name'] = implode('/', array_column(GetPart($value['itemid']), 'name'));
  1439. $data[] = $value;
  1440. }
  1441. return json_show(0, "获取成功", $data);
  1442. }
  1443. //贵金属种类列表
  1444. public function linst()
  1445. {
  1446. $data = [];
  1447. foreach ($this->gold as $key => $value) {
  1448. $v = [];
  1449. $v['type'] = $key;
  1450. $v['type_cn'] = $value;
  1451. $data[] = $v;
  1452. }
  1453. return json_show(0, "获取成功", $data);
  1454. }
  1455. //分类列表
  1456. public function wlist()
  1457. {
  1458. $this->post = $this->request->filter('trim')->post();
  1459. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
  1460. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
  1461. $where = [["is_del", "=", 0], ['level', "=", 3]];
  1462. $cat_name = isset($this->post['cat_name']) && $this->post['cat_name'] !== "" ? trim($this->post['cat_name']) : "";
  1463. if ($cat_name !== "") {
  1464. $where[] = ['cat_name', "like", "%$cat_name%"];
  1465. }
  1466. $search = isset($this->post['search']) && $this->post['search'] !== "" ? trim($this->post['search']) : "";
  1467. if ($search !== "") {
  1468. $where[] = ['search', "like", "%$search%"];
  1469. }
  1470. $pid = isset($this->post['pid']) && $this->post['pid'] !== "" ? intval($this->post['pid']) : "";
  1471. if ($pid !== "") {
  1472. $where[] = ['pid', "=", $pid];
  1473. }
  1474. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  1475. if ($status !== "") {
  1476. $where[] = ['status', "=", $status];
  1477. }
  1478. $count = Db::name("cat")->where($where)->count();
  1479. $total = ceil($count / $size);
  1480. $page = $page >= $total ? $total : $page;
  1481. $list = Db::name('cat')->where($where)->page($page, $size)->select();
  1482. $data = [];
  1483. foreach ($list as $value) {
  1484. $temp = isset($value['id']) && $value['id'] != 0 ? made($value['id']) : [];
  1485. $value['item'] = array_column($temp, 'id');
  1486. $data[] = $value;
  1487. }
  1488. return json_show(0, "获取成功", ['list' => $data, 'count' => $count]);
  1489. }
  1490. //分类列表-全部
  1491. public function title()
  1492. {
  1493. $this->post = $this->request->filter('trim')->post();
  1494. $where = [["is_del", "=", 0]];
  1495. $cat_name = isset($this->post['cat_name']) && $this->post['cat_name'] !== "" ? trim($this->post['cat_name']) : "";
  1496. if ($cat_name !== "") $where[] = ['cat_name', "like", "%$cat_name%"];
  1497. $pid = isset($this->post['pid']) && $this->post['pid'] !== "" ? intval($this->post['pid']) : "";
  1498. if ($pid !== "") $where[] = ["pid", "=", $pid];
  1499. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  1500. if ($status !== "") $where[] = ['status', "=", $status];
  1501. $list = Db::name('cat')
  1502. ->where($where)
  1503. ->select()
  1504. ->toArray();
  1505. return json_show(0, "获取成功", $list);
  1506. }
  1507. //判断是否允许修改成本信息和基础信息
  1508. public function checkIsUpdate()
  1509. {
  1510. $spuCode = $this->request->post('spuCode', '', 'trim');
  1511. if ($spuCode == '') return json_show(1004, '成本商品编号不能为空');
  1512. $is_allow_update = 1;
  1513. //检查是否有上线记录
  1514. $rs = Db::name('good_platform')
  1515. ->field('id')
  1516. ->where(['spuCode' => $spuCode, 'is_del' => 0])
  1517. ->whereNotIn('exam_status', [0, 8])
  1518. ->find();
  1519. if (!empty($rs)) $is_allow_update = 0;
  1520. else {
  1521. $rs = PlatformYouzan::field('id')
  1522. ->where(['spuCode' => $spuCode, 'is_del' => PlatformYouzan::$del_normal])
  1523. ->whereNotIn('exam_status', [PlatformYouzan::$exam_status_8, PlatformYouzan::$exam_status_2])
  1524. ->findOrEmpty()
  1525. ->isEmpty();
  1526. if (!$rs) $is_allow_update = 0;
  1527. }
  1528. return json_show(0, '请求成功', ['is_allow_update' => $is_allow_update]);
  1529. }
  1530. //上线商品复制
  1531. public function copy()
  1532. {
  1533. $this->post = $this->request->filter('trim')->post();
  1534. $supcode = isset($this->post['spuCode']) && $this->post['spuCode'] != "" ? trim($this->post['spuCode']) : "";
  1535. if ($supcode == "") {
  1536. return json_show(1004, "参数spuCode不能为空");
  1537. }
  1538. $data = Db::name("good_basic")->where(["spuCode" => $supcode, "is_del" => 0])->find();
  1539. if ($data == false) {
  1540. return json_show(1004, "未找到商品数据");
  1541. }
  1542. // $token = isset($this->post['token']) && $this->post['token'] != '' ? trim($this->post['token']) : "";
  1543. // if ($token == '') {
  1544. // return json_show(105, "参数token不能为空");
  1545. // }
  1546. // $user =GetUserInfo($token);
  1547. // if(empty($user)||$user['code']!=0){
  1548. // return json_show(102,"用户数据不存在");
  1549. // }
  1550. $createrid = $this->request->user['uid'];
  1551. $creater = $this->request->user['nickname'];
  1552. $nake = Db::name("good_nake")->where(["spuCode" => $supcode, "is_del" => 0])->select()->toArray();
  1553. $ladd = [];
  1554. $newCode = makeNo("SKU");
  1555. if (!empty($nake)) {
  1556. foreach ($nake as $value) {
  1557. $tmp = [];
  1558. $tmp['spuCode'] = $newCode;
  1559. $tmp['min_num'] = $value['min_num'];
  1560. $tmp['nake_fee'] = $value['nake_fee'];
  1561. $tmp['cost_fee'] = $value['cost_fee'];
  1562. $tmp['delivery_fee'] = $value['delivery_fee'];
  1563. $tmp['cert_fee'] = $value['cert_fee'];
  1564. $tmp['mark_fee'] = $value['mark_fee'];
  1565. $tmp['package_fee'] = $value['package_fee'];
  1566. $tmp['other_fee'] = $value['other_fee'];
  1567. $tmp['nake_total'] = $value['nake_total'];
  1568. $tmp['creater_id'] = $createrid;
  1569. $tmp['creater'] = $creater;
  1570. $tmp['is_del'] = $value['is_del'];
  1571. $tmp['addtime'] = date("Y-m-d H:i:s");
  1572. $tmp['updatetime'] = date("Y-m-d H:i:s");
  1573. $ladd[] = $tmp;
  1574. }
  1575. }
  1576. $spec = Db::name("good_spec")
  1577. ->where(["spuCode" => $supcode, "is_del" => 0])
  1578. ->select()
  1579. ->toArray();
  1580. $specArr = [];
  1581. if (!empty($spec)) {
  1582. foreach ($spec as $value) {
  1583. $tmp = [];
  1584. $tmp['spuCode'] = $newCode;
  1585. $tmp['spec_id'] = $value['spec_id'];
  1586. $tmp['spec_value_id'] = $value['spec_value_id'];
  1587. $tmp['is_del'] = $value['is_del'];
  1588. $tmp['addtime'] = date("Y-m-d H:i:s");
  1589. $tmp['updatetime'] = date("Y-m-d H:i:s");
  1590. $specArr[] = $tmp;
  1591. }
  1592. }
  1593. Db::startTrans();
  1594. try {
  1595. unset($data['id']);
  1596. $data['spuCode'] = $newCode;
  1597. $data['createrid'] = $createrid;
  1598. $data['creater'] = $creater;
  1599. $data['status'] = 7;
  1600. $data['addtime'] = date("Y-m-d H:i:s");
  1601. $data['updatetime'] = date("Y-m-d H:i:s");
  1602. $cre = Db::name("good_basic")->insert($data);
  1603. if ($cre) {
  1604. //修改状态,添加待办
  1605. ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
  1606. "order_code" => $newCode,//咨询单详情编号
  1607. "status" => 0,//这里的status是之前的值
  1608. "action_remark" => '',//备注
  1609. "action_type" => "create"//新建create,编辑edit,更改状态status
  1610. ], "SPCB", 7, $data);
  1611. ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
  1612. "order_type" => 'SPCB',
  1613. "order_code" => $newCode,//咨询单详情编号
  1614. "order_id" => Db::name("good_basic")->getLastInsID(),
  1615. "order_status" => 7,
  1616. "before_status" => 0,
  1617. 'holder_id' => $data['createrid'],
  1618. 'person_id' => Db::name('supplier')->where(['code' => $this->request->user['supplierNo'], 'is_del' => 0])->value('personid'),
  1619. ]);
  1620. if (!empty($ladd)) {
  1621. $na = Db::name("good_nake")->insertAll($ladd);
  1622. if ($na == 0) {
  1623. Db::rollback();
  1624. return json_show(1005, "成本数据复制失败");
  1625. }
  1626. }
  1627. if (!empty($specArr)) {
  1628. $sp = Db::name("good_spec")->insertAll($specArr);
  1629. if ($sp == 0) {
  1630. Db::rollback();
  1631. return json_show(1005, "规格数据复制失败");
  1632. }
  1633. }
  1634. Db::commit();
  1635. return json_show(0, "复制数据成功", ["spuCode" => $newCode]);
  1636. } else {
  1637. Db::rollback();
  1638. return json_show(1005, "数据复制失败");
  1639. }
  1640. } catch (\Exception $e) {
  1641. Db::rollback();
  1642. return json_show(1004, $e->getMessage());
  1643. }
  1644. }
  1645. //上线商品详情
  1646. public function info()
  1647. {
  1648. $this->post = $this->request->filter('trim')->post();
  1649. $skucode = isset($this->post['skuCode']) && $this->post['skuCode'] != "" ? trim($this->post['skuCode']) : "";
  1650. if ($skucode == "") {
  1651. return json_show(1005, "参数skuCode不能为空");
  1652. }
  1653. $good_platform = Db::name("good_platform")->where(['skuCode' => $skucode, "is_del" => 0])->find();
  1654. if ($good_platform == false) {
  1655. return json_show(1004, "未找到商品数据");
  1656. }
  1657. $data = Db::name("good")->where(["spuCode" => $good_platform['spuCode'], "is_del" => 0])->find();
  1658. if ($data == false) {
  1659. return json_show(1004, "未找到商品数据");
  1660. }
  1661. $plat = Db::name("platform")->where(["id" => $good_platform['platform_code']])->find();
  1662. $data['skuCode'] = $good_platform['skuCode'];
  1663. $data['platform_code'] = $good_platform['id'];
  1664. $data['platform_code_en'] = isset($plat['platform_code']) ? $plat['platform_code'] : "";
  1665. $data['platform_name'] = isset($plat['platform_name']) ? $plat['platform_name'] : "";
  1666. $data['online_reason'] = $good_platform['online_reason'];
  1667. $data['online_time'] = $good_platform['online_time'];
  1668. $data['online_remark'] = $good_platform['online_remark'];
  1669. $data['exam_status'] = $good_platform['exam_status'];
  1670. $data['is_online'] = $good_platform['is_online'];
  1671. $data['plat_code'] = $good_platform['plat_code'];
  1672. $data['exclusive'] = makeExcluse($data['is_exclusive']);
  1673. $unit = Db::name("unit")->where(["id" => $data['good_unit']])->find();
  1674. $data['unit'] = isset($unit['unit']) ? $unit['unit'] : '';
  1675. $data['cat_info'] = made($data['cat_id'], []);
  1676. $spec = Db::name("good_spec")->where(["spuCode" => $good_platform['spuCode'], "is_del" => 0])->select()->toArray();
  1677. $supplier = Db::name("supplier")->where(["code" => $data['supplierNo']])->find();
  1678. $data['supplierName'] = isset($supplier['name']) ? $supplier['name'] : "";
  1679. $data['noble_name'] = isset($data['noble_metal']) && $data['noble_metal'] != 0 ? $this->noble[$data['noble_metal']] : "";
  1680. $company = Db::name("business")->where(["companyNo" => $data['companyNo']])->find();
  1681. $data['company'] = isset($company['company']) ? $company['company'] : "";
  1682. if ($data['brand_id'] != 0) {
  1683. $brand = Db::name("brand")->where(["id" => $data['brand_id']])->find();
  1684. $data["brand_name"] = isset($brand['brand_name']) ? $brand['brand_name'] : "";
  1685. } else {
  1686. $data["brand_name"] = "";
  1687. $data["brand_id"] = "";
  1688. }
  1689. $data['origin_place_cn'] = "";
  1690. $data['delivery_place_cn'] = "";
  1691. if ($data['delivery_place'] !== "") {
  1692. $place = ["provice_code" => "", "city_code" => "", "area_code" => ""];
  1693. list($place['provice_code'], $place['city_code'], $place['area_code']) = explode(",", $data['delivery_place']);
  1694. $data['delivery_place_cn'] = GetAddr(json_encode($place));
  1695. }
  1696. if ($data['origin_place'] !== "") {
  1697. $place = ["provice_code" => "", "city_code" => "", "area_code" => ""];
  1698. list($place['provice_code'], $place['city_code'], $place['area_code']) = explode(",", $data['origin_place']);
  1699. $data['origin_place_cn'] = GetAddr(json_encode($place));
  1700. }
  1701. $excluse = makeExcluse($data['is_exclusive']);
  1702. $data['exclusive'] = $excluse;
  1703. $data["good_info_img"] = $data['good_info_img'] != "" ? $data['good_info_img'] : [];
  1704. $data["good_img"] = $data['good_img'] != "" ? $data['good_img'] : [];
  1705. $speclist = [];
  1706. if (!empty($spec)) {
  1707. foreach ($spec as $value) {
  1708. $temp = [];
  1709. $temp['id'] = $value['id'];
  1710. $temp['spuCode'] = $value['spuCode'];
  1711. $temp['spec_id'] = $value['spec_id'];
  1712. $temp['spec_value_id'] = $value['spec_value_id'];
  1713. $temp['is_del'] = $value['is_del'];
  1714. $sp = Db::name("specs")->where(["id" => $value['spec_id']])->find();
  1715. $temp['spec_name'] = isset($sp["spec_name"]) ? $sp["spec_name"] : "";
  1716. $spv = Db::name("spec_value")->where(["id" => $value['spec_value_id']])->find();
  1717. $temp['spec_value'] = isset($spv["spec_value"]) ? $spv["spec_value"] : "";
  1718. $speclist[] = $temp;
  1719. }
  1720. }
  1721. $data["speclist"] = empty($speclist) ? [] : $speclist;
  1722. $ladder = Db::name("good_ladder")->where(['skuCode' => $skucode, "is_del" => 0])->select()->toArray();
  1723. $data["ladderlist"] = !empty($ladder) ? $ladder : [];
  1724. $nakelist = Db::name("good_nake")->where(['spuCode' => $good_platform['spuCode'], "is_del" => 0])->select()->toArray();
  1725. // $catinfo = Db::name("cat")->where(["id"=>$data['cat_id']])->find();
  1726. $cat_top_list = $data['cat_info'];
  1727. $cat_top_id = isset($cat_top_list[0]['id']) ? $cat_top_list[0]['id'] : 0;
  1728. // $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  1729. $gold_price = 0;
  1730. if ($data['is_gold_price'] == 1 && $cat_top_id == 6) {
  1731. $gold_price = Db::name("gold_price1")->where(["type" => $data['noble_metal'], "status" => 1, "is_del" => 0])->order("addtime desc")->value('price', 0);
  1732. }
  1733. $data['gold_price'] = $gold_price;
  1734. $nakearry = [];
  1735. if (!empty($nakelist)) {
  1736. //实时金价
  1737. foreach ($nakelist as $value) {
  1738. $value['sale_price'] = $value['nake_total'];
  1739. //计算最终售价
  1740. if ($data['is_gold_price'] == 1 && $cat_top_id == 6) {
  1741. //普通商品:直接用财务提交的售价字段;
  1742. //贵金属( 商品重量* 最新金价 + 工艺费(财务定价提交的)* 商品重量+包装费+加标费+证书费+产品裸价+其他费用)=商品库商品直接下单的售价
  1743. $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']);
  1744. }
  1745. $nakearry[] = $value;
  1746. }
  1747. }
  1748. $proof = Db::name("good_proof")->where(["spuCode" => $good_platform['spuCode'], "is_del" => 0])->order("updatetime desc")->field("id,proof_type,proof_url")->find();
  1749. $data['proof'] = isset($proof) && $proof != false ? $proof : [];
  1750. $data["nakelist"] = $nakearry;
  1751. //补充采购员字段
  1752. //成本表里的创建人,也是线上商品的采购人,为了防止混淆,给creater取个别名
  1753. $temp_basic_info = Db::name('good_basic')
  1754. ->field('id,createrid purchase_id,creater purchase')
  1755. ->where(['spuCode' => $data['spuCode'], 'is_del' => 0])
  1756. ->find();
  1757. $data['purchase_id'] = $temp_basic_info['purchase_id'];
  1758. $data['purchase'] = $temp_basic_info['purchase'];
  1759. return json_show(0, "获取成功", $data);
  1760. }
  1761. }