Goodup.php 126 KB

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