Goodup.php 89 KB

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