Goodup.php 150 KB

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