Good.php 82 KB

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