Good.php 99 KB

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