Goodup.php 109 KB

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