Goodup.php 111 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203
  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. $gold=[];
  914. if ($data['is_gold_price'] == 1) {
  915. $gold = Db::name("gold_price1")->where(["type" => $data['noble_metal'], "status" => 1, "is_del" => 0])->order("addtime desc")->find();
  916. }
  917. $data['gold_price'] =isset($gold["price"])?$gold["price"]:0;
  918. $speclist=[];
  919. if(!empty($spec)){
  920. foreach ($spec as $value){
  921. $temp=[];
  922. $temp['id']=$value['id'];
  923. $temp['spuCode']=$value['spuCode'];
  924. $temp['spec_id']=$value['spec_id'];
  925. $temp['spec_value_id']=$value['spec_value_id'];
  926. $temp['is_del']=$value['is_del'];
  927. $sp = Db::name("specs")->where(["id"=>$value['spec_id']])->find();
  928. $temp['spec_name']=isset($sp["spec_name"]) ? $sp["spec_name"]:"";
  929. $spv = Db::name("spec_value")->where(["id"=>$value['spec_value_id']])->find();
  930. $temp['spec_value']=isset($spv["spec_value"]) ? $spv["spec_value"]:"";
  931. $speclist[]=$temp;
  932. }
  933. }
  934. $data["speclist"]=empty($speclist)?[]:$speclist;
  935. // $nake=[];
  936. $nakelist = Db::name("good_nake")->where(['spuCode'=>$supcode,"is_del"=>0])->select()->toArray();
  937. // $catinfo = Db::name("cat")->where(["id"=>$data['cat_id']])->find();
  938. // $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  939. $nakearry=[];
  940. if(!empty($nakelist)){
  941. foreach ($nakelist as $value) {
  942. $nakearry[] = $value;
  943. }
  944. }
  945. $data["nakelist"]=$nakearry;
  946. return app_show(0,"获取成功",$data);
  947. }
  948. public function delall(){
  949. $supcode = isset($this->post['codes'])&&!empty($this->post['codes'])? $this->post['codes']:"";
  950. if($supcode==""){
  951. return error_show(1004,"参数codes不能为空");
  952. }
  953. $data = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->select()->toArray();
  954. if(empty($data)){
  955. return error_show(1004,"未找到商品数据");
  956. }
  957. $up= Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->save(["is_del"=>1]);
  958. if($up){
  959. return app_show(0,"更新成功");
  960. }else{
  961. return error_show(1005,"更新失败");
  962. }
  963. }
  964. //添加上线商品
  965. public function online(){
  966. $platform =isset($this->post['platform'])&&!empty($this->post['platform'])? $this->post['platform']:"";
  967. if($platform==""){
  968. return error_show(1004,"参数codes不能为空");
  969. }
  970. $spuCode =isset($this->post['codes'])&&!empty($this->post['codes'])? $this->post['codes']:"";
  971. if($spuCode===''){
  972. return error_show(1004,"参数codes不能为空");
  973. }
  974. $datas = Db::name("good_basic")->where(["spuCode"=>$spuCode,"is_del"=>0])->select()->toArray();
  975. if(empty($datas)){
  976. return error_show(1004,"未找到商品数据");
  977. }
  978. $online_reason = isset($this->post['online_reason'])&&$this->post['online_reason']!==""? trim($this->post['online_reason']):"";
  979. if($online_reason===""){
  980. return error_show(1004,"参数online_reason不能为空");
  981. }
  982. $online_remark= isset($this->post['online_remark'])&&$this->post['online_remark']!==""? trim($this->post['online_remark']):"";
  983. if($online_remark===""){
  984. return error_show(1004,"参数online_remark不能为空");
  985. }
  986. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  987. if($token==''){
  988. return error_show(105,"参数token不能为空");
  989. }
  990. $user =GetUserInfo($token);
  991. if(empty($user)||$user['code']!=0){
  992. return error_show(1002,"用户数据不存在");
  993. }
  994. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  995. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  996. $data=[];
  997. $isonline=[];
  998. $i=0;
  999. foreach ($spuCode as $value){
  1000. $count = Db::name("good_nake")->where(["spuCode"=>$value,"is_del"=>0])->count();
  1001. $ist =Db::name("good_platform")->where(["spuCode"=>$value,"platform_code"=>$platform,"is_del"=>0])->find();
  1002. if($ist){
  1003. $god=Db::name("good_basic")->where(["spuCode"=>$value,"is_del"=>0])->find();
  1004. if($god){
  1005. $tp=[];
  1006. $tp['spuCode']=$value;
  1007. $tp['good_name']=$god['good_name'];
  1008. $tp['good_img']=$god['good_thumb_img'];
  1009. $tp['exam_status']=$ist['exam_status'];
  1010. $spec = Db::name("good_spec")->where(["spuCode"=>$value,"is_del"=>0])->select()->toArray();
  1011. $speclist=[];
  1012. if(!empty($spec)){
  1013. foreach ($spec as $val){
  1014. $temp=[];
  1015. $temp['id']=$val['id'];
  1016. $temp['spuCode']=$val['spuCode'];
  1017. $temp['spec_id']=$val['spec_id'];
  1018. $temp['spec_value_id']=$val['spec_value_id'];
  1019. $temp['is_del']=$val['is_del'];
  1020. $sp = Db::name("specs")->where(["id"=>$val['spec_id']])->find();
  1021. $temp['spec_name']=isset($sp["spec_name"]) ? $sp["spec_name"]:"";
  1022. $spv = Db::name("spec_value")->where(["id"=>$val['spec_value_id']])->find();
  1023. $temp['spec_value']=isset($spv["spec_value"]) ? $spv["spec_value"]:"";
  1024. $speclist[]=$temp;
  1025. }
  1026. }
  1027. $tp["speclist"]=empty($speclist)?[]:$speclist;
  1028. $isonline[]=$tp;
  1029. }
  1030. }
  1031. //改变编码规则,将原来的skuCode后两位换成序列号
  1032. //str_pad字符串填充
  1033. $skuCode = makeNo("SN");
  1034. $skuCode = substr($skuCode, 0, -2) . str_pad($i, 2, '0', STR_PAD_LEFT);
  1035. $data[]=[
  1036. "spuCode"=>$value,
  1037. "skuCode"=>$skuCode,
  1038. "platform_code"=>$platform,
  1039. "online_reason"=>$online_reason,
  1040. "online_remark"=>$online_remark,
  1041. "exam_status"=>$count>0 ?2:1,
  1042. "is_online"=>0,
  1043. "status"=>1,
  1044. "is_del"=>0,
  1045. "creater"=>$creater,
  1046. "createrid"=>$createrid,
  1047. "addtime"=>date("Y-m-d H:i:s"),
  1048. "updatetime"=>date("Y-m-d H:i:s")
  1049. ];
  1050. $i++;
  1051. }
  1052. if(!empty($isonline)){
  1053. return app_show(1009,"存在已上线产品",$isonline);
  1054. }
  1055. Db::startTrans();
  1056. $create =Db::name("good_platform")->insertAll($data);
  1057. if($create){
  1058. foreach ($datas as $value){
  1059. $iso = Db::name("good")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->find();
  1060. if($iso==false){
  1061. unset($value['id']);
  1062. $value['creater']=$creater;
  1063. $value['createrid']=$createrid;
  1064. $value['addtime']=date("Y-m-d H:i:s");
  1065. $value['updatetime']=date("Y-m-d H:i:s");
  1066. }else{
  1067. $value['id']=$iso['id'];
  1068. $value['creater']=$creater;
  1069. $value['createrid']=$createrid;
  1070. $value['updatetime']=date("Y-m-d H:i:s");
  1071. }
  1072. $up =Db::name("good")->save($value);
  1073. if(!$up){
  1074. Db::rollback();
  1075. return error_show(1004,"提交失败");
  1076. }
  1077. //添加审核记录
  1078. //修改状态,添加待办
  1079. $skuCodes = array_column($data, 'skuCode', 'spuCode');
  1080. ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
  1081. "order_code" => $skuCodes[$value['spuCode']],//编号
  1082. "status" => 2,//待产品审核
  1083. "action_remark" => '',//备注
  1084. "action_type" => "create"//新建create,编辑edit,更改状态status
  1085. ], "SPSX", $value['status'], $value);
  1086. ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
  1087. "order_type" => 'SPSX',
  1088. "order_code" => $skuCodes[$value['spuCode']],//咨询单详情编号
  1089. "order_id" => isset($value['id']) ? $value['id'] : 0,
  1090. "order_status" => 2,//待产品审核
  1091. ]);
  1092. }
  1093. Db::commit();
  1094. return app_show(0,"提交成功");
  1095. }else{
  1096. Db::rollback();
  1097. return error_show(1004,"提交失败");
  1098. }
  1099. }
  1100. //审核
  1101. public function online_exam(){
  1102. $skuCode = isset($this->post['skuCode'])&&$this->post['skuCode']!==""?trim($this->post['skuCode']):"";
  1103. if($skuCode===""){
  1104. return error_show(1004,"参数skuCode不能为空");
  1105. }
  1106. $platform = Db::name("good_platform")->where(["skuCode"=>$skuCode,"is_del"=>0])->find();
  1107. if($platform==false){
  1108. return error_show(1004,"未找到数据");
  1109. }
  1110. $exam_status=isset($this->post['exam_status'])&&$this->post['exam_status']!==""?intval($this->post['exam_status']):"";
  1111. // if($exam_status===""){
  1112. // return error_show(1004,"参数exam_status不能为空");
  1113. // }
  1114. if($exam_status==3){
  1115. $online_time= isset($this->post['online_time'])&&$this->post['online_time']!==""?$this->post['online_time']:"";
  1116. if($online_time===""){
  1117. return error_show(1004,"参数online_time不能为空");
  1118. }
  1119. $platform['online_time']=$online_time;
  1120. }
  1121. if($exam_status==6){
  1122. $good_code= isset($this->post['plat_code'])&&$this->post['plat_code']!==""?trim($this->post['plat_code']):"";
  1123. if($good_code===""){
  1124. return error_show(1004,"参数plat_code不能为空");
  1125. }
  1126. $is_exit = Db::name("good_platform")->where(["plat_code"=>$good_code,"is_del"=>0])->find();
  1127. if(($is_exit!=false && $is_exit['id'] !=$platform['id'])|| $is_exit==false){
  1128. $platform['plat_code']=$good_code;
  1129. }else{
  1130. return error_show(1004,"平台订单号 {$good_code} 已存在");
  1131. }
  1132. }
  1133. $exam_remark = isset($this->post['exam_remark'])&&$this->post['exam_remark']!==""?trim($this->post['exam_remark']):"";
  1134. $platform['exam_status']=$exam_status;
  1135. $platform['updatetime']=date("Y-m-d H:i:s");
  1136. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1137. if($token==''){
  1138. return error_show(105,"参数token不能为空");
  1139. }
  1140. $user =GetUserInfo($token);
  1141. if(empty($user)||$user['code']!=0){
  1142. return error_show(1002,"用户数据不存在");
  1143. }
  1144. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1145. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1146. Db::startTrans();
  1147. try {
  1148. $up = Db::name("good_platform")->save($platform);
  1149. if($up){
  1150. $data=[
  1151. "code"=>$platform['skuCode'],
  1152. "exam_status"=>$exam_status,
  1153. "type"=>2,
  1154. "exam_id"=>$createrid,
  1155. "exam_name"=>$creater,
  1156. "exam_remark"=>$exam_remark,
  1157. "addtime"=>date("Y-m-d H:i:s")
  1158. ];
  1159. $inr=Db::name("good_exam")->insert($data);
  1160. if($inr){
  1161. ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
  1162. "order_code" => $skuCode,//编号
  1163. "status" => $exam_status,
  1164. "action_remark" => '',//备注
  1165. "action_type" => "status"//新建create,编辑edit,更改状态status
  1166. ], "SPSX", $exam_status, $platform);
  1167. ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
  1168. "order_type" => 'SPSX',
  1169. "order_code" => $skuCode,//咨询单详情编号
  1170. "order_id" => $platform['id'],
  1171. "order_status" => $exam_status,
  1172. ]);
  1173. Db::commit();
  1174. return app_show(0,"审核成功");
  1175. }else{
  1176. Db::rollback();
  1177. return error_show(1004,"审核失败");
  1178. }
  1179. }else{
  1180. Db::rollback();
  1181. return error_show(1004,"审核失败");
  1182. }
  1183. }catch (\Exception $e){
  1184. Db::rollback();
  1185. return error_show(1004,$e->getMessage());
  1186. }
  1187. }
  1188. //财务定价
  1189. public function editladder(){
  1190. $skuCode = isset($this->post['skuCode'])&&$this->post['skuCode']!==""?trim($this->post['skuCode']):"";
  1191. if($skuCode===""){
  1192. return error_show(1004,"参数skuCode不能为空");
  1193. }
  1194. $platform = Db::name("good_platform")->where(["skuCode"=>$skuCode,"is_del"=>0])->find();
  1195. if($platform==false){
  1196. return error_show(1004,"未找到数据");
  1197. }
  1198. $good_ladder = isset($this->post['good_ladder'])&&!empty($this->post['good_ladder'])?$this->post['good_ladder']:"";
  1199. if($good_ladder==""){
  1200. return error_show(1004,"参数good_ladder不能为空");
  1201. }
  1202. $proof_type = isset($this->post['proof_type'])&&$this->post['proof_type']!==""?intval($this->post['proof_type']):"";
  1203. if($proof_type===""){
  1204. return error_show(1004,"参数proof_type不能为空");
  1205. }
  1206. $proof_url = isset($this->post['proof_url'])&&$this->post['proof_url']!==""?trim($this->post['proof_url']):"";
  1207. if($proof_url===""){
  1208. return error_show(1004,"参数proof_url不能为空");
  1209. }
  1210. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1211. if($token==''){
  1212. return error_show(105,"参数token不能为空");
  1213. }
  1214. $user =GetUserInfo($token);
  1215. if(empty($user)||$user['code']!=0){
  1216. return error_show(1002,"用户数据不存在");
  1217. }
  1218. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1219. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1220. $platform['exam_status']=4;
  1221. $platform['updatetime']=date("Y-m-d H:i:s");
  1222. Db::startTrans();
  1223. try {
  1224. foreach ($good_ladder as $value){
  1225. $lemp=[];
  1226. isset($value["id"])&&$value["id"]!=""?$lemp['id']=$value['id']:"";
  1227. $lemp['skuCode']=$skuCode;
  1228. $lemp['min_num'] = $value['min_num'];
  1229. $lemp['max_num'] = 0;
  1230. $lemp['sale_price'] = $value['sale_price'];
  1231. $lemp['market_price'] = $value['market_price'];
  1232. $lemp['market_platform'] = $value['market_platform'];
  1233. $lemp['cost_fee'] = $value['cost_fee'];
  1234. $lemp['status'] = $value['status'];
  1235. $lemp['is_del'] = isset($value['is_del'])?$value['is_del']:0;
  1236. isset($value["id"])&&$value["id"]!=""?"": $lemp['addtime'] = date("Y-m-d H:i:s");
  1237. $lemp['updatetime'] =date("Y-m-d H:i:s");
  1238. $count = Db::name("good_ladder")->save($lemp);
  1239. if($count==false){
  1240. Db::rollback();
  1241. return app_show(1004,"商品起订价修改失败");
  1242. }
  1243. }
  1244. $up = Db::name("good_platform")->save($platform);
  1245. if($up){
  1246. $proof=[
  1247. 'spuCode'=>$platform['spuCode'],
  1248. 'proof_type'=>$proof_type,
  1249. 'proof_url'=>$proof_url,
  1250. 'is_del'=>0,
  1251. "creater"=>$creater,
  1252. "createrid"=>$createrid,
  1253. "addtime"=>date("Y-m-d H:i:s"),
  1254. "updatetime"=>date("Y-m-d H:i:s")
  1255. ];
  1256. $inproof = Db::name("good_proof")->insert($proof);
  1257. if($inproof==false){
  1258. Db::rollback();
  1259. return app_show(1004,"商品凭证新建失败");
  1260. }
  1261. $data=[
  1262. "code"=>$platform['skuCode'],
  1263. "type"=>2,
  1264. "exam_status"=>4,
  1265. "exam_id"=>$createrid,
  1266. "exam_name"=>$creater,
  1267. "exam_remark"=>'',
  1268. "addtime"=>date("Y-m-d H:i:s")
  1269. ];
  1270. $inr=Db::name("good_exam")->insert($data);
  1271. if($inr){
  1272. //修改状态,添加待办
  1273. ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
  1274. "order_code" => $skuCode,
  1275. "status" => 4,//待财务审核定价
  1276. "action_remark" => '',//备注
  1277. "action_type" => "status"//新建create,编辑edit,更改状态status
  1278. ], "SPSX", 4, $value);
  1279. ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
  1280. "order_type" => 'SPSX',
  1281. "order_code" => $skuCode,
  1282. "order_id" => $platform['id'],
  1283. "order_status" => 4,//待财务审核定价
  1284. ]);
  1285. Db::commit();
  1286. return app_show(0,"审核成功");
  1287. }else{
  1288. Db::rollback();
  1289. return error_show(1004,"审核失败");
  1290. }
  1291. }else{
  1292. Db::rollback();
  1293. return error_show(1004,"审核失败");
  1294. }
  1295. }catch (\Exception $e){
  1296. Db::rollback();
  1297. return error_show(1004,$e->getMessage());
  1298. }
  1299. }
  1300. public function prooflist(){
  1301. $page = isset($this->post['page']) && $this->post['page'] !==""? intval($this->post['page']):"1";
  1302. $size = isset($this->post['size']) && $this->post['size'] !==""? intval($this->post['size']):"10";
  1303. $where =[["is_del","=",0]];
  1304. $spuCode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):"";
  1305. if($spuCode!==""){
  1306. $where[]=["spuCode","like","%$spuCode%"];
  1307. }
  1308. $count = Db::name("good_proof")->where($where)->count();
  1309. $total = ceil($count / $size);
  1310. $page = $page >= $total ? $total : $page;
  1311. $data = Db::name("good_proof")->where($where)->page($page,$size)->order("addtime desc")->select();
  1312. return app_show(0,"获取成功",['list'=>$data,"count"=>$count]);
  1313. }
  1314. /**
  1315. *
  1316. */
  1317. public function againOnline(){
  1318. $skuCode = isset($this->post['skuCode'])&&$this->post['skuCode']!==""?trim($this->post['skuCode']):"";
  1319. if($skuCode===""){
  1320. return error_show(1004,"参数skuCode不能为空");
  1321. }
  1322. $platform = Db::name("good_platform")->where(["skuCode"=>$skuCode,"is_del"=>0])->find();
  1323. if($platform==false){
  1324. return error_show(1004,"未找到数据");
  1325. }
  1326. if($platform["exam_status"]!=7&&$platform["exam_status"]!=8){
  1327. return error_show(1004,"商品状态有误");
  1328. }
  1329. $nake =Db::name("good_nake")->where(["spuCode"=>$platform['spuCode'],"is_del"=>0])->select()->toArray();
  1330. $platform['exam_status'] = empty($nake)?1:2;
  1331. $platform['updatetime'] = date("Y-m-d H:i:s");
  1332. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1333. if($token==''){
  1334. return error_show(105,"参数token不能为空");
  1335. }
  1336. $user =GetUserInfo($token);
  1337. if(empty($user)||$user['code']!=0){
  1338. return error_show(1002,"用户数据不存在");
  1339. }
  1340. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1341. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1342. Db::startTrans();
  1343. try {
  1344. $save =Db::name("good_platform")->save($platform);
  1345. if($save){
  1346. $data=[
  1347. "code"=>$platform['skuCode'],
  1348. "type"=>2,
  1349. "exam_status"=>$platform['exam_status'] ,
  1350. "exam_id"=>$createrid,
  1351. "exam_name"=>$creater,
  1352. "exam_remark"=>'',
  1353. "addtime"=>date("Y-m-d H:i:s")
  1354. ];
  1355. $inr=Db::name("good_exam")->insert($data);
  1356. if($inr){
  1357. Db::commit();
  1358. return app_show(0,"审核成功");
  1359. }
  1360. }
  1361. Db::rollback();
  1362. return error_show(1004,"审核失败");
  1363. }catch (\Exception $e){
  1364. Db::rollback();
  1365. return error_show(1004,$e->getMessage());
  1366. }
  1367. }
  1368. public function copy(){
  1369. $supcode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):"";
  1370. if($supcode==""){
  1371. return error_show(1004,"参数spuCode不能为空");
  1372. }
  1373. $data = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->find();
  1374. if($data==false){
  1375. return error_show(1004,"未找到商品数据");
  1376. }
  1377. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1378. if($token==''){
  1379. return error_show(105,"参数token不能为空");
  1380. }
  1381. $user =GetUserInfo($token);
  1382. if(empty($user)||$user['code']!=0){
  1383. return error_show(102,"用户数据不存在");
  1384. }
  1385. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1386. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1387. $nake = Db::name("good_nake")->where(["spuCode"=>$supcode,"is_del"=>0])->select()->toArray();
  1388. $ladd=[];
  1389. $newCode =makeNo("SKU");
  1390. if(!empty($nake)){
  1391. foreach ($nake as $value){
  1392. $tmp=[];
  1393. $tmp['spuCode']=$newCode;
  1394. $tmp['min_num']=$value['min_num'];
  1395. $tmp['nake_fee'] = $value['nake_fee'];
  1396. $tmp['cost_fee'] = $value['cost_fee'];
  1397. $tmp['delivery_fee'] = $value['delivery_fee'];
  1398. $tmp['cert_fee'] = $value['cert_fee'];
  1399. $tmp['mark_fee'] = $value['mark_fee'];
  1400. $tmp['package_fee'] = $value['package_fee'];
  1401. $tmp['other_fee'] = $value['other_fee'];
  1402. $tmp['nake_total'] =$value['nake_total'];
  1403. $tmp['creater_id']=$createrid;
  1404. $tmp['creater']=$creater;
  1405. $tmp['is_del']=$value['is_del'];
  1406. $tmp['addtime']=date("Y-m-d H:i:s");
  1407. $tmp['updatetime']=date("Y-m-d H:i:s");
  1408. $ladd[]=$tmp;
  1409. }
  1410. }
  1411. $spec = Db::name("good_spec")->where(["spuCode"=>$supcode,"is_del"=>0])->select()->toArray();
  1412. $specArr=[];
  1413. if(!empty($spec)){
  1414. foreach ($spec as $value){
  1415. $tmp=[];
  1416. $tmp['spuCode']=$newCode;
  1417. $tmp['spec_id']=$value['spec_id'];
  1418. $tmp['spec_value_id']=$value['spec_value_id'];
  1419. $tmp['is_del']=$value['is_del'];
  1420. $tmp['addtime']=date("Y-m-d H:i:s");
  1421. $tmp['updatetime']=date("Y-m-d H:i:s");
  1422. $specArr[]=$tmp;
  1423. }
  1424. }
  1425. Db::startTrans();
  1426. try {
  1427. unset($data['id']);
  1428. $data['spuCode']=$newCode;
  1429. $data['createrid']=$createrid;
  1430. $data['creater']=$creater;
  1431. $data['status']=7;
  1432. $data['addtime']=date("Y-m-d H:i:s");
  1433. $data['updatetime']=date("Y-m-d H:i:s");
  1434. $cre = Db::name("good_basic")->insert($data);
  1435. if($cre){
  1436. if(!empty($ladd)){
  1437. $na = Db::name("good_nake")->insertAll($ladd);
  1438. if($na==0){
  1439. Db::rollback();
  1440. return error_show(1005,"成本数据复制失败");
  1441. }
  1442. }
  1443. if(!empty($specArr)){
  1444. $sp = Db::name("good_spec")->insertAll($specArr);
  1445. if($sp==0){
  1446. Db::rollback();
  1447. return error_show(1005,"规格数据复制失败");
  1448. }
  1449. }
  1450. Db::commit();
  1451. return app_show(0,"复制数据成功",["spuCode"=>$newCode]);
  1452. }else{
  1453. Db::rollback();
  1454. return error_show(1005,"数据复制失败");
  1455. }
  1456. }catch (\Exception $e){
  1457. Db::rollback();
  1458. return error_show(1004,$e->getMessage());
  1459. }
  1460. }
  1461. public function edit(){
  1462. $supcode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):"";
  1463. if($supcode==""){
  1464. return error_show(1004,"参数spuCode不能为空");
  1465. }
  1466. $data = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->find();
  1467. if($data==false){
  1468. return error_show(1004,"未找到商品数据");
  1469. }
  1470. if ($data['status'] != 6 && $data['status'] != 7 && $data['status'] != 8) {
  1471. return error_show(1004,"商品状态有误");
  1472. }
  1473. $good_name= isset($this->post['good_name'])&&$this->post['good_name']!="" ? trim($this->post['good_name']):"";
  1474. if($good_name==""){
  1475. return error_show(1004,"商品名称不能为空");
  1476. }
  1477. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? intval($this->post['cat_id']):"";
  1478. if($cat_id==''){
  1479. return error_show(1004,"商品分类不能为空");
  1480. }
  1481. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"0";
  1482. // if($brandid==''){
  1483. // return error_show(1004,"商品品牌不能为空");
  1484. // }
  1485. $unit = isset($this->post['unit'])&&$this->post['unit']!=""? trim($this->post['unit']):"";
  1486. if($unit==''){
  1487. return error_show(1004,"商品单位不能为空");
  1488. }
  1489. $good_type = isset($this->post['good_type'])&&$this->post['good_type']!==""? intval($this->post['good_type'])
  1490. :"";
  1491. if($good_type===''){
  1492. return error_show(1004,"参数good_type不能为空");
  1493. }
  1494. $moq=0;
  1495. $customized=0;
  1496. if($good_type==1){
  1497. $moq = isset($this->post['moq'])&&$this->post['moq']!==""? intval($this->post['moq']):"";
  1498. if($moq===''){
  1499. return error_show(1004,"定制商品起订量不能为空");
  1500. }
  1501. $customized = isset($this->post['customized'])&&$this->post['customized']!==""? intval($this->post['customized']):"";
  1502. if($customized===''){
  1503. return error_show(1004,"参数customized不能为空");
  1504. }
  1505. }
  1506. $is_exclusive = isset($this->post['is_exclusive'])&&$this->post['is_exclusive']!==""? intval($this->post['is_exclusive']):"";
  1507. if($is_exclusive===''){
  1508. return error_show(1004,"参数is_exclusive不能为空");
  1509. }
  1510. // $customized = isset($this->post['customized'])&&$this->post['customized']!==""? intval($this->post['customized']):"";
  1511. // if($customized===''){
  1512. // return error_show(1004,"参数customized不能为空");
  1513. // }
  1514. $tax = isset($this->post['tax'])&&$this->post['tax']!==""? intval($this->post['tax']):"";
  1515. if($tax===''){
  1516. return error_show(1004,"参数tax不能为空");
  1517. }
  1518. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
  1519. if($supplierNo==''){
  1520. return error_show(1004,"参数supplierNo不能为空");
  1521. }
  1522. $good_size = isset($this->post['good_size'])&&$this->post['good_size']!=""? trim($this->post['good_size'])
  1523. :"";
  1524. if($good_size==''){
  1525. return error_show(1004,"参数good_size不能为空");
  1526. }
  1527. $company_id = isset($this->post['companyNo'])&&$this->post['companyNo']!=""? trim($this->post['companyNo'])
  1528. :"";
  1529. if($company_id==''){
  1530. return error_show(1004,"参数companyNo不能为空");
  1531. }
  1532. $is_auth = isset($this->post['is_auth'])&&$this->post['is_auth']!==""? intval($this->post['is_auth']):"";
  1533. if($is_auth===''){
  1534. return error_show(1004,"参数is_auth不能为空");
  1535. }
  1536. $auth_img = isset($this->post['auth_img'])&&$this->post['auth_img']!=""? trim($this->post['auth_img']):"";
  1537. // if($auth_img==''){
  1538. // return error_show(1004,"商品不能为空");
  1539. // }
  1540. $after_sales = isset($this->post['after_sales'])&&$this->post['after_sales']!=""? trim($this->post['after_sales']):"";
  1541. if($after_sales==""){
  1542. return error_show(1004,"参数after_sales不能为空");
  1543. }
  1544. $craft_desc = isset($this->post['craft_desc'])&&$this->post['craft_desc']!=""? trim($this->post['craft_desc']):"";
  1545. $good_remark = isset($this->post['good_remark'])&&$this->post['good_remark']!=""? trim($this->post['good_remark']):"";
  1546. if($good_remark===""){
  1547. return error_show(1004,"参数good_remark不能为空");
  1548. }
  1549. $weight = isset($this->post['weight'])&&$this->post['weight']!==""? floatval($this->post['weight']):"";
  1550. if($weight===""){
  1551. return error_show(1004,"参数weight不能为空");
  1552. }
  1553. $packing_way = isset($this->post['packing_way'])&&$this->post['packing_way']!==""? trim($this->post['packing_way']):"";
  1554. if($packing_way===""){
  1555. return error_show(1004,"参数packing_way不能为空");
  1556. }
  1557. $packing_size = isset($this->post['packing_size'])&&$this->post['packing_size']!==""? trim($this->post['packing_size']):"";
  1558. if($packing_size===""){
  1559. return error_show(1004,"参数packing_size不能为空");
  1560. }
  1561. $packing_spec = isset($this->post['packing_spec'])&&$this->post['packing_spec']!==""? trim($this->post['packing_spec']):"";
  1562. if($packing_spec===""){
  1563. return error_show(1004,"参数packing_spec不能为空");
  1564. }
  1565. $packing_weight = isset($this->post['packing_weight'])&&$this->post['packing_weight']!==""? floatval($this->post['packing_weight']):"";
  1566. if($packing_weight===""){
  1567. return error_show(1004,"参数packing_weight不能为空");
  1568. }
  1569. $packing_list = isset($this->post['packing_list'])&&$this->post['packing_list']!==""? trim($this->post['packing_list']):"";
  1570. if($packing_list===""){
  1571. return error_show(1004,"参数packing_list不能为空");
  1572. }
  1573. $good_bar = isset($this->post['good_bar'])&&$this->post['good_bar']!==""? trim($this->post['good_bar']):"";
  1574. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  1575. if($supply_area===""){
  1576. return error_show(1004,"参数supply_area不能为空");
  1577. }
  1578. $delivery_place = isset($this->post['delivery_place'])&&$this->post['delivery_place']!==""? $this->post['delivery_place']:"";
  1579. if($delivery_place===""){
  1580. return error_show(1004,"参数delivery_place不能为空");
  1581. }
  1582. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!==""? $this->post['origin_place']:"";
  1583. if($origin_place===""){
  1584. return error_show(1004,"参数origin_place不能为空");
  1585. }
  1586. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!==""? intval($this->post['delivery_day']):"";
  1587. if($delivery_day===""){
  1588. return error_show(1004,"参数delivery_day不能为空");
  1589. }
  1590. $lead_time = isset($this->post['lead_time'])&&$this->post['lead_time']!==""? intval($this->post['lead_time'])
  1591. :"0";
  1592. // if($lead_time===""){
  1593. // return error_show(1004,"参数lead_time不能为空");
  1594. // }
  1595. $sample_day = isset($this->post['sample_day'])&&$this->post['sample_day']!==""? intval($this->post['sample_day']):"0";
  1596. // if($sample_day===""){
  1597. // return error_show(1004,"参数sample_day不能为空");
  1598. // }
  1599. $sample_fee = isset($this->post['sample_fee'])&&$this->post['sample_fee']!==""? floatval($this->post['sample_fee']):"0";
  1600. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""? trim($this->post['good_img']):"";
  1601. if($good_img===""){
  1602. return error_show(1004,"参数good_img不能为空");
  1603. }
  1604. $good_thumb_img = isset($this->post['good_thumb_img'])&&$this->post['good_thumb_img']!==""? trim($this->post['good_thumb_img']):"";
  1605. if($good_thumb_img===""){
  1606. return error_show(1004,"参数good_thumb_img不能为空");
  1607. }
  1608. $good_info_img = isset($this->post['good_info_img'])&&!empty($this->post['good_info_img'])? trim($this->post['good_info_img']):"";
  1609. if($good_info_img===""){
  1610. return error_show(1004,"参数good_info_img不能为空");
  1611. }
  1612. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!==""? floatval($this->post['cert_fee']):"0";
  1613. $packing_fee = isset($this->post['packing_fee'])&&$this->post['packing_fee']!==""? floatval($this->post['packing_fee']):"0";
  1614. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!==""? floatval($this->post['cost_fee']):"0";
  1615. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!==""? floatval($this->post['mark_fee']):"0";
  1616. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!==""? floatval($this->post['demo_fee']):"0";
  1617. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!==""? floatval($this->post['open_fee']):"0";
  1618. $noble_metal = isset($this->post['noble_metal'])&&$this->post['noble_metal']!==""? intval($this->post['noble_metal']):"0";
  1619. $noble_weight = isset($this->post['noble_weight'])&&$this->post['noble_weight']!==""? floatval($this->post['noble_weight']):"0";
  1620. $is_gold_price= isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!==""? intval($this->post['is_gold_price']):"0";
  1621. $market_price = isset($this->post['market_price'])&&$this->post['market_price']!==""? floatval($this->post['market_price']):"";
  1622. $cgd_gold_price = isset($this->post['cgd_gold_price'])&&$this->post['cgd_gold_price']!==""? floatval($this->post['cgd_gold_price']):"0";
  1623. if($market_price===""){
  1624. return error_show(1004,"参数market_price不能为空");
  1625. }
  1626. $nake_price = isset($this->post['nake_price'])&&$this->post['nake_price']!==""? floatval($this->post['nake_price']):"0";
  1627. $config = isset($this->post['config'])&&$this->post['config']!==""? trim($this->post['config']):"";
  1628. $other_config = isset($this->post['other_config'])&&$this->post['other_config']!==""? trim($this->post['other_config']):"";
  1629. $is_diff = isset($this->post['is_diff'])&&$this->post['is_diff']!==""? intval($this->post['is_diff']):"0";
  1630. $is_stock = isset($this->post['is_stock'])&&$this->post['is_stock']!==""? intval($this->post['is_stock']):"0";
  1631. // $is_step = isset($this->post['is_step'])&&$this->post['is_step']!==""? intval($this->post['is_step']):"";
  1632. // if($is_step===""){
  1633. // return error_show(1004,"参数is_step不能为空");
  1634. // }
  1635. $good_ladder = isset($this->post['good_ladder'])&&!empty($this->post['good_ladder'])? $this->post['good_ladder']:"";
  1636. // if($is_step==1 && $good_ladder==""){
  1637. // return error_show(1004,"启用阶梯,阶梯价不能为空");
  1638. // }
  1639. $speclist = isset($this->post['speclist'])&&!empty($this->post['speclist'])? $this->post['speclist']:"";
  1640. Db::startTrans();
  1641. try {
  1642. $temp=[
  1643. "good_name"=>$good_name,
  1644. "cat_id"=>$cat_id,
  1645. 'brand_id'=>$brandid,
  1646. "good_unit"=>$unit,
  1647. "good_type"=>$good_type,
  1648. "companyNo"=>$company_id,
  1649. "moq"=>$moq,
  1650. "is_exclusive"=>$is_exclusive,
  1651. "customized"=>$customized,
  1652. "tax"=>$tax,
  1653. "supplierNo"=>$supplierNo,
  1654. "is_auth"=>$is_auth,
  1655. "good_size"=>$good_size,
  1656. "auth_img"=>$auth_img,
  1657. "after_sales"=>$after_sales,
  1658. "craft_desc"=>$craft_desc,
  1659. "good_remark"=>$good_remark,
  1660. "weight"=>$weight,
  1661. "packing_way"=>$packing_way,
  1662. "packing_size"=>$packing_size,
  1663. "packing_spec"=>$packing_spec,
  1664. "packing_list"=>$packing_list,
  1665. "packing_weight"=>$packing_weight,
  1666. "good_bar"=>$good_bar,
  1667. "supply_area"=>$supply_area,
  1668. "delivery_place"=>$delivery_place,
  1669. "origin_place"=>$origin_place,
  1670. "delivery_day"=>$delivery_day,
  1671. "lead_time"=>$lead_time,
  1672. "sample_day"=>$sample_day,
  1673. "sample_fee"=>$sample_fee,
  1674. "good_img"=>$good_img,
  1675. "good_thumb_img"=>$good_thumb_img,
  1676. "good_info_img"=>$good_info_img,
  1677. "cert_fee"=>$cert_fee,
  1678. "packing_fee"=>$packing_fee,
  1679. "is_diff"=>$is_diff,
  1680. "config"=>$config,
  1681. "other_config"=>$other_config,
  1682. "is_stock"=>$is_stock,
  1683. "cost_fee"=>$cost_fee,
  1684. "mark_fee"=>$mark_fee,
  1685. "demo_fee"=>$demo_fee,
  1686. "open_fee"=>$open_fee,
  1687. "noble_metal"=>$noble_metal,
  1688. "noble_weight"=>$noble_weight,
  1689. "is_gold_price"=>$is_gold_price,
  1690. "market_price"=>$market_price,
  1691. "nake_price"=>$nake_price,
  1692. "cgd_gold_price"=>$cgd_gold_price,
  1693. "is_step" => count($good_ladder) > 1 ? 1 : 0,
  1694. "status"=>"0",
  1695. "updatetime"=>date("Y-m-d H:i:s")
  1696. ];
  1697. $field = array_diff_assoc($temp,$data);
  1698. $temp['field_change'] =empty($field)?"":json_encode(array_keys($field));
  1699. $up = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->save($temp);
  1700. $var = array_diff($temp,$data);
  1701. $json = json_encode($var,JSON_UNESCAPED_UNICODE);
  1702. $dat = json_encode($data,JSON_UNESCAPED_UNICODE);
  1703. if($up){
  1704. ChangeLog::logAdd(3,$data['spuCode'],$dat,$json,$this->post['token'],$this->post);
  1705. if($speclist!=="" && !empty($speclist)){
  1706. foreach ($speclist as $value){
  1707. $lemp=[];
  1708. isset($value["id"])&&$value["id"]!=''?$lemp['id']=$value['id']:"";
  1709. $lemp['spuCode']=$supcode;
  1710. $lemp['spec_id'] = $value['spec_id'];
  1711. $lemp['spec_value_id'] = $value['spec_value_id'];
  1712. $lemp['is_del'] = isset($value['is_del'])?$value['is_del']:0;
  1713. isset($value["id"])&&$value["id"]!=''?"": $lemp['addtime'] = date("Y-m-d H:i:s");
  1714. $lemp['updatetime'] =date("Y-m-d H:i:s");
  1715. $count = Db::name("good_spec")->save($lemp);
  1716. if($count==false){
  1717. Db::rollback();
  1718. return app_show(1004,"商品规格值修改失败");
  1719. }
  1720. }
  1721. }
  1722. if($good_ladder!=="" && !empty($good_ladder)){
  1723. $user =GetUserInfo($this->post['token']);//获取用户信息,下面更新成本表的创建人
  1724. $top_cat_id = made($cat_id);//获取所有分类
  1725. $top_cat_id = isset($top_cat_id[0]['id']) ? $top_cat_id[0]['id'] : 0;//获取顶级分类id
  1726. foreach ($good_ladder as $value){
  1727. $lemp=[];
  1728. isset($value["id"])&&$value["id"]!=''?$lemp['id']=$value['id']:"";
  1729. $lemp['spuCode']=$supcode;
  1730. $lemp['min_num'] = $value['min_num'];
  1731. $lemp['nake_fee'] = $value['nake_fee'];
  1732. $lemp['cost_fee'] = $value['cost_fee'];
  1733. $lemp['delivery_fee'] = $value['delivery_fee'];
  1734. $lemp['cert_fee'] = $value['cert_fee'];
  1735. $lemp['mark_fee'] = $value['mark_fee'];
  1736. $lemp['package_fee'] = $value['package_fee'];
  1737. $lemp['other_fee'] = $value['other_fee'];
  1738. if ($is_gold_price == 1 && $top_cat_id == 6) {
  1739. $gold =Db::name("gold_price1")->where(["type"=>$noble_metal,"status"=>1,"is_del"=>0])->order("addtime desc")->find();
  1740. //$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'];
  1741. //成本合计=贵金属重量*供应商采购金价 + 工艺费*贵金属重量+加标费+包装费+证书费+成本裸价+运费+其他费用
  1742. //成本总计启用实时金价时,采用供应商实时金价
  1743. $lemp['nake_total'] =$noble_weight *$gold['price']+ $value['cost_fee'] * $noble_weight +
  1744. $value['mark_fee'] + $value['package_fee'] + $value['cert_fee'] + $value['nake_fee'] + $value['delivery_fee'] + $value['other_fee'];
  1745. }else{
  1746. $lemp['nake_total'] =$value['nake_fee']+$value['delivery_fee']+$value['cert_fee']+$value['mark_fee']+$value['package_fee']+$value['other_fee'];
  1747. }
  1748. $lemp['creater_id'] = isset($user["data"]['id']) ? $user["data"]['id'] : 0;
  1749. $lemp['creater'] = isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1750. $lemp['is_del'] = isset($value['is_del'])?$value['is_del']:0;
  1751. isset($value["id"])&&$value["id"]!=''?"": $lemp['addtime'] = date("Y-m-d H:i:s");
  1752. $lemp['updatetime'] =date("Y-m-d H:i:s");
  1753. $count = Db::name("good_nake")->save($lemp);
  1754. if($count==false){
  1755. Db::rollback();
  1756. return app_show(1004,"商品规成本修改失败");
  1757. }
  1758. }
  1759. }
  1760. Db::commit();
  1761. return app_show(0,"更新成功");
  1762. }else{
  1763. Db::rollback();
  1764. return error_show(1005,"更新失败");
  1765. }
  1766. }catch (\Exception $e){
  1767. Db::rollback();
  1768. return error_show(1004,$e->getMessage());
  1769. }
  1770. }
  1771. public function checkPrice(){
  1772. $spuCode=isset($this->post['spuCode'])&&$this->post['spuCode']!=""? trim($this->post['spuCode']):"";
  1773. if($spuCode==""){
  1774. return error_show(1005,"参数spuCode不能为空");
  1775. }
  1776. $good =Db::name("good_basic")->where(["spuCode"=>$spuCode,"is_del"=>0])->find();
  1777. if($good==false){
  1778. return error_show(1005,"商品数据未找到");
  1779. }
  1780. $num=isset($this->post['min_num'])&&$this->post['min_num']!=="" ? intval($this->post['min_num']):"";
  1781. if($num==""){
  1782. return error_show(1005,"参数min_num不能为空");
  1783. }
  1784. $nakelist = Db::name("good_nake")->where(['spuCode'=>$spuCode,"is_del"=>0])->where([["min_num","<=",$num]])
  1785. ->order("min_num desc")->find();
  1786. if($nakelist==false){
  1787. $nakelist = Db::name("good_nake")->where(['spuCode'=>$spuCode,"is_del"=>0])->order("min_num asc")->find();
  1788. return error_show(1010,"起订量不足{$nakelist['min_num']}");
  1789. }
  1790. $catinfo = Db::name("cat")->where(["id"=>$good['cat_id']])->find();
  1791. $budget = isset($catinfo['sale_rate']) ? $catinfo['sale_rate']/100:0;
  1792. $top_cat_id = made($catinfo['id']);//获取所有分类
  1793. $top_cat_id = isset($top_cat_id[0]['id']) ? $top_cat_id[0]['id'] : 0;//获取顶级分类id
  1794. $sale_cost_fee = 0;
  1795. if ($good['is_gold_price'] == 1 && $top_cat_id == 6) {
  1796. // $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'];
  1797. //系统售价=(贵金属重量*供应商采购金价 + 工艺费*贵金属重量+加标费+包装费+证书费+成本裸价+运费+其他费用)/(1-成本售价/100)
  1798. $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);
  1799. //计算工艺费
  1800. //销售工艺费=(( 商品重量* 供应商采购金价 + 采购成本工艺费* 商品重量+包装费+加标费+证书费+产品裸价+其他费用)/(1-成本售价/100)-(包装费+加标费+证书费+产品裸价0+运费+其他费用) )/商品重量-供应商采购金价
  1801. $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"];
  1802. }else{
  1803. $saleprice = ($nakelist['mark_fee'] + $nakelist['package_fee'] + $nakelist['cert_fee'] + $nakelist['delivery_fee'] + $nakelist['nake_fee']) / (1 - $budget);
  1804. }
  1805. return app_show(0, "获取成功", ["sale_price" => round($saleprice, 2), 'new_cost_fee' => round($sale_cost_fee, 2)]);
  1806. }
  1807. //咨询成交商品池 添加上线商品
  1808. public function onlineZixunGoods()
  1809. {
  1810. $param = $this->request->only(['platform', 'codes', 'online_reason', 'online_remark', 'token'], 'post', 'trim');
  1811. $val = Validate::rule([
  1812. 'platform|所选上线平台' => 'require|number|gt:0',
  1813. 'codes|所选上线商品编号' => 'require',
  1814. 'online_reason|上线原因' => 'require',
  1815. 'online_remark|上线备注' => 'require',
  1816. 'token' => 'require',
  1817. ]);
  1818. if (!$val->check($param)) return error_show(1004, $val->getError());
  1819. $good_zixun_list = Db::name("good_zixun")
  1820. ->where(["is_del" => 0])
  1821. ->whereIn('spuCode', $param['codes'])
  1822. ->column('*', 'spuCode');
  1823. if (empty($good_zixun_list)) return error_show(1004, "未找到相关咨询商品数据");
  1824. $a = array_diff($param['codes'], array_keys($good_zixun_list));
  1825. if (!empty($a)) return error_show(1005, '该咨询商品不存在' . implode(',', $a));
  1826. $isonline = Db::name("good_platform")
  1827. ->alias('gp')
  1828. ->field('gp.id,gp.spuCode,gb.good_name,gb.good_img,gp.exam_status')
  1829. ->where(["gp.platform_code" => $param['platform'], "gp.is_del" => 0])
  1830. ->whereIn('gp.spuCode', $param['codes'])
  1831. ->leftJoin('good_basic gb', 'gb.spuCode=gp.spuCode AND gb.is_del=0')
  1832. ->select()
  1833. ->toArray();
  1834. if (!empty($isonline)) {
  1835. foreach ($isonline as &$v) {
  1836. $spec = Db::name("good_spec")
  1837. ->where(["spuCode" => $v['spuCode'], "is_del" => 0])
  1838. ->select()
  1839. ->toArray();
  1840. $speclist = [];
  1841. if (!empty($spec)) {
  1842. foreach ($spec as $val) {
  1843. $temp = [];
  1844. $temp['id'] = $val['id'];
  1845. $temp['spuCode'] = $val['spuCode'];
  1846. $temp['spec_id'] = $val['spec_id'];
  1847. $temp['spec_value_id'] = $val['spec_value_id'];
  1848. $temp['is_del'] = $val['is_del'];
  1849. $sp = Db::name("specs")->where(["id" => $val['spec_id']])->find();
  1850. $temp['spec_name'] = isset($sp["spec_name"]) ? $sp["spec_name"] : "";
  1851. $spv = Db::name("spec_value")->where(["id" => $val['spec_value_id']])->find();
  1852. $temp['spec_value'] = isset($spv["spec_value"]) ? $spv["spec_value"] : "";
  1853. $speclist[] = $temp;
  1854. }
  1855. }
  1856. $v["speclist"] = empty($speclist) ? [] : $speclist;
  1857. }
  1858. return app_show(1009, "存在已上线产品", $isonline);
  1859. }
  1860. if (!empty($isonline)) return error_show(1005, $isonline['spuCode'] . '该商品已在商品成本管理中,请在商品成本管理菜单提交上线!');
  1861. $user = GetUserInfo($param['token']);
  1862. if (empty($user) || $user['code'] != 0) return error_show(1002, "用户数据不存在");
  1863. $createrid = isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1864. $creater = isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1865. $data = $good_insert_data = $good_basic_insert_data = $good_spec_insert_data = [];
  1866. $i = 0;
  1867. $all_nakes = Db::name("good_nake")
  1868. ->where(["is_del" => 0])->fetchSql()
  1869. ->whereIn('spuCode', $param['codes'])
  1870. ->group('spuCode')
  1871. ->column('count(`id`) total', 'spuCode');
  1872. $all_good = Db::name('good')
  1873. ->where('is_del', 0)
  1874. ->whereIn('spuCode', $param['codes'])
  1875. ->column('id', 'spuCode');
  1876. if (!empty($all_good)) return error_show(1004, '请从商品成本提交该商品上线');
  1877. $all_good_basic = Db::name('good_basic')
  1878. ->where('is_del', 0)
  1879. ->whereIn('spuCode', $param['codes'])
  1880. ->column('id', 'spuCode');
  1881. if (!empty($all_good_basic)) return error_show(1004, '请从商品成本提交该商品上线');
  1882. foreach ($param['codes'] as $value) {
  1883. //改变编码规则,将原来的skuCode后两位换成序列号
  1884. //str_pad字符串填充
  1885. $skuCode = makeNo("SN");
  1886. $skuCode = substr($skuCode, 0, -2) . str_pad($i, 2, '0', STR_PAD_LEFT);
  1887. $data[] = [
  1888. "spuCode" => $value,
  1889. "skuCode" => $skuCode,
  1890. "platform_code" => $param['platform'],
  1891. "online_reason" => $param['online_reason'],
  1892. "online_remark" => $param['online_remark'],
  1893. "exam_status" => isset($all_nakes[$value]) ? ($all_nakes[$value] > 0 ? 2 : 1) : 1,
  1894. "is_online" => 0,
  1895. "status" => 1,
  1896. "is_del" => 0,
  1897. "creater" => $creater,
  1898. "createrid" => $createrid,
  1899. "addtime" => date("Y-m-d H:i:s"),
  1900. "updatetime" => date("Y-m-d H:i:s")
  1901. ];
  1902. //good表
  1903. if (!isset($all_good[$value])) {
  1904. $good_insert_data[] = [
  1905. 'spuCode' => $good_zixun_list[$value]['spuCode'],
  1906. 'good_code' => $good_zixun_list[$value]['good_code'],
  1907. 'good_name' => $good_zixun_list[$value]['good_name'],
  1908. 'cat_id' => $good_zixun_list[$value]['cat_id'],
  1909. 'brand_id' => $good_zixun_list[$value]['brand_id'],
  1910. 'good_unit' => $good_zixun_list[$value]['good_unit'],
  1911. 'good_type' => $good_zixun_list[$value]['good_type'],
  1912. 'companyNo' => $good_zixun_list[$value]['companyNo'],
  1913. 'moq' => $good_zixun_list[$value]['moq'],
  1914. 'customized' => $good_zixun_list[$value]['customized'],
  1915. 'tax' => $good_zixun_list[$value]['tax'],
  1916. 'supplierNo' => $good_zixun_list[$value]['supplierNo'],
  1917. 'is_auth' => $good_zixun_list[$value]['is_auth'],
  1918. 'is_stock' => '',
  1919. 'auth_img' => $good_zixun_list[$value]['auth_img'],
  1920. 'after_sales' => '',
  1921. 'craft_desc' => $good_zixun_list[$value]['craft_desc'],
  1922. 'good_remark' => $good_zixun_list[$value]['good_remark'],
  1923. 'good_size' => '',
  1924. 'weight' => $good_zixun_list[$value]['weight'],
  1925. 'packing_way' => '',
  1926. 'packing_size' => '',
  1927. 'packing_spec' => '',
  1928. 'packing_list' => '',
  1929. 'packing_weight' => '',
  1930. 'good_bar' => '',
  1931. 'supply_area' => $good_zixun_list[$value]['supply_area'],
  1932. 'delivery_place' => '',
  1933. 'origin_place' => '',
  1934. 'delivery_day' => 0,
  1935. 'lead_time' => '',
  1936. 'sample_day' => '',
  1937. 'sample_fee' => '',
  1938. 'good_img' => $good_zixun_list[$value]['good_img'],
  1939. 'good_thumb_img' => $good_zixun_list[$value]['good_thumb_img'],
  1940. 'good_info_img' => $good_zixun_list[$value]['good_info_img'],
  1941. 'cert_fee' => '',
  1942. 'packing_fee' => '',
  1943. 'cost_fee' => '',
  1944. 'mark_fee' => '',
  1945. 'demo_fee' => '',
  1946. 'open_fee' => '',
  1947. 'noble_metal' => $good_zixun_list[$value]['noble_metal'],
  1948. 'noble_weight' => $good_zixun_list[$value]['good_weight'],
  1949. 'is_gold_price' => $good_zixun_list[$value]['is_gold_price'],
  1950. 'cgd_gold_price' => '',
  1951. 'market_price' => '',
  1952. 'nake_price' => '',
  1953. 'is_step' => '',
  1954. 'is_online' => '',
  1955. 'status' => 1,//待完善成本
  1956. 'createrid' => $createrid,
  1957. 'creater' => $creater,
  1958. 'is_del' => 0,
  1959. 'field_change' => '',
  1960. 'addtime' => date('Y-m-d H:i:s'),
  1961. 'updatetime' => date('Y-m-d H:i:s'),
  1962. 'is_exclusive' => '',
  1963. 'is_diff' => $good_zixun_list[$value]['is_diff'],
  1964. 'config' => $good_zixun_list[$value]['config'],
  1965. 'other_config' => $good_zixun_list[$value]['other_config'],
  1966. ];
  1967. }
  1968. //good_basic表
  1969. if (!isset($all_good_basic[$value])) {
  1970. $good_basic_insert_data[] = [
  1971. 'spuCode' => $good_zixun_list[$value]['spuCode'],
  1972. 'good_code' => $good_zixun_list[$value]['good_code'],
  1973. 'good_name' => $good_zixun_list[$value]['good_name'],
  1974. 'cat_id' => $good_zixun_list[$value]['cat_id'],
  1975. 'brand_id' => $good_zixun_list[$value]['brand_id'],
  1976. 'companyNo' => $good_zixun_list[$value]['companyNo'],
  1977. 'good_unit' => $good_zixun_list[$value]['good_unit'],
  1978. 'good_type' => $good_zixun_list[$value]['good_type'],
  1979. 'moq' => $good_zixun_list[$value]['moq'],
  1980. 'customized' => $good_zixun_list[$value]['customized'],
  1981. 'tax' => $good_zixun_list[$value]['tax'],
  1982. 'supplierNo' => $good_zixun_list[$value]['supplierNo'],
  1983. 'is_auth' => $good_zixun_list[$value]['is_auth'],
  1984. 'auth_img' => $good_zixun_list[$value]['auth_img'],
  1985. 'after_sales' => '',
  1986. 'craft_desc' => $good_zixun_list[$value]['craft_desc'],
  1987. 'good_remark' => $good_zixun_list[$value]['good_remark'],
  1988. 'weight' => $good_zixun_list[$value]['weight'],
  1989. 'packing_way' => '',
  1990. 'packing_size' => '',
  1991. 'packing_spec' => '',
  1992. 'packing_list' => '',
  1993. 'packing_weight' => '',
  1994. 'good_bar' => '',
  1995. 'supply_area' => $good_zixun_list[$value]['supply_area'],
  1996. 'delivery_place' => '',
  1997. 'origin_place' => '',
  1998. 'delivery_day' => '',
  1999. 'lead_time' => '',
  2000. 'sample_day' => '',
  2001. 'sample_fee' => '',
  2002. 'good_img' => '',//$good_zixun_list[$value]['good_img'],
  2003. 'good_thumb_img' => $good_zixun_list[$value]['good_thumb_img'],
  2004. 'good_info_img' => $good_zixun_list[$value]['good_img'],//商品主图对应到商品详情
  2005. 'cert_fee' => '',
  2006. 'packing_fee' => '',
  2007. 'cost_fee' => '',
  2008. 'mark_fee' => '',
  2009. 'demo_fee' => '',
  2010. 'open_fee' => '',
  2011. 'noble_metal' => $good_zixun_list[$value]['noble_metal'],
  2012. 'noble_weight' => $good_zixun_list[$value]['good_weight'],
  2013. 'is_gold_price' => $good_zixun_list[$value]['is_gold_price'],
  2014. 'cgd_gold_price' => '',
  2015. 'market_price' => '',
  2016. 'nake_price' => '',
  2017. 'is_step' => '',
  2018. 'is_online' => '',
  2019. 'status' => 8,//咨询商品待编辑
  2020. 'createrid' => $createrid,
  2021. 'creater' => $creater,
  2022. 'field_change' => '',
  2023. 'is_del' => 0,
  2024. 'addtime' => date('Y-m-d H:i:s'),
  2025. 'updatetime' => date('Y-m-d H:i:s'),
  2026. 'is_diff' => $good_zixun_list[$value]['is_diff'],
  2027. 'config' => $good_zixun_list[$value]['config'],
  2028. 'other_config' => $good_zixun_list[$value]['other_config'],
  2029. ];
  2030. }
  2031. //good_spec
  2032. if (!empty($good_zixun_list[$value]['specinfo'])) {
  2033. $spec_list = json_decode($good_zixun_list[$value]['specinfo'], true);
  2034. foreach ($spec_list as $spec) {
  2035. $temp = Db::name('good_spec')
  2036. ->field('id')
  2037. ->where(['spuCode' => $value, 'spec_id' => $spec['specid'], 'spec_value_id' => $spec['spec_value_id'], 'is_del' => 0])
  2038. ->find();
  2039. if (!empty($temp)) {
  2040. $good_spec_insert_data[] = [
  2041. 'spuCode' => $value,
  2042. 'spec_id' => $spec['specid'],
  2043. 'spec_value_id' => $spec['spec_value_id'],
  2044. 'is_del' => 0,
  2045. 'addtime' => date('Y-m-d H:i:s'),
  2046. 'updatetime' => date('Y-m-d H:i:s'),
  2047. ];
  2048. }
  2049. }
  2050. }
  2051. $i++;
  2052. }
  2053. if (!empty($isonline)) {
  2054. return app_show(1009, "存在已上线产品", $isonline);
  2055. }
  2056. Db::startTrans();
  2057. try {
  2058. $create = Db::name("good_platform")->insertAll($data);
  2059. Db::name("good_zixun")
  2060. ->where(["is_del" => 0, 'status' => 1])
  2061. ->whereIn('spuCode', $param['codes'])
  2062. ->update(['status' => 2, 'updatetime' => date('Y-m-d H:i:s')]);
  2063. if (!empty($good_insert_data)) Db::name('good')->insertAll($good_insert_data);
  2064. if (!empty($good_basic_insert_data)) Db::name('good_basic')->insertAll($good_basic_insert_data);
  2065. if (!empty($good_spec_insert_data)) Db::name('good_spec')->insertAll($good_spec_insert_data);
  2066. if ($create) {
  2067. foreach ($good_zixun_list as $value) {
  2068. //添加审核记录
  2069. //修改状态,添加待办
  2070. $skuCodes = array_column($data, 'skuCode', 'spuCode');
  2071. ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
  2072. "order_code" => $skuCodes[$value['spuCode']],//
  2073. "status" => 2,//待产品审核
  2074. "action_remark" => '',//备注
  2075. "action_type" => "create"//新建create,编辑edit,更改状态status
  2076. ], "SPSX", $value['status'], $value);
  2077. ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
  2078. "order_type" => 'SPSX',
  2079. "order_code" => $skuCodes[$value['spuCode']],//
  2080. "order_id" => isset($value['id']) ? $value['id'] : 0,
  2081. "order_status" => 2,//待产品审核
  2082. ]);
  2083. }
  2084. Db::commit();
  2085. return app_show(0, "提交成功");
  2086. } else {
  2087. Db::rollback();
  2088. return error_show(1004, "提交失败");
  2089. }
  2090. } catch (Exception $exception) {
  2091. Db::rollback();
  2092. return error_show(1005, $exception->getMessage());
  2093. }
  2094. }
  2095. }