Goodup.php 143 KB

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