Good.php 98 KB

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