Goodup.php 86 KB

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