Goodup.php 82 KB

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