Good.php 98 KB

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