Goodup.php 92 KB

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