Goodup.php 84 KB

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