Goodup.php 93 KB

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