Goodup.php 85 KB

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