Goodup.php 87 KB

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