Goodup.php 153 KB

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