Goodup.php 129 KB

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