Goodup.php 152 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040
  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. if($data['status']==1){
  945. return error_show(1004,"商品已审核通过");
  946. }
  947. $status = isset($this->post['status'])&&$this->post['status']!=="" ? intval($this->post['status']):"";
  948. // if($status===""){
  949. // return error_show(1004,"参数status不能为空");
  950. // }
  951. $remark = isset($this->post['remark'])&&$this->post['remark']!=="" ? trim($this->post['remark']):"";
  952. // if($remark===""){
  953. // return error_show(1004,"参数remark不能为空");
  954. // }
  955. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  956. if($token==''){
  957. return error_show(105,"参数token不能为空");
  958. }
  959. $user =GetUserInfo($token);
  960. if(empty($user)||$user['code']!=0){
  961. return error_show(1002,"用户数据不存在");
  962. }
  963. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  964. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  965. Db::startTrans();
  966. try {
  967. if($data['status']==3 && $status==1){
  968. $online = Db::name("good_platform")->where(["spuCode"=>$supcode,"is_del"=>0])->find();
  969. if($online) {
  970. $onl= Db::name("good_platform")->where(["spuCode" => $supcode, "is_del" => 0])->save(["exam_status" => 2, "updatetime" => date("Y-m-d H:i:s")]);
  971. if ($onl == false) {
  972. Db::rollback();
  973. return error_show(1004, "审核失败");
  974. }
  975. ActionLog::logAdd($this->post['token'], [
  976. "order_code" =>$online['skuCode'],//咨询单详情编号
  977. "status" => $online['exam_status'],//这里的status是之前的值
  978. "action_remark" => '',//备注
  979. "action_type" => "edit"//新建create,编辑edit,更改状态status
  980. ], "SPSX", 2, ["exam_status" => 2, "updatetime" => date("Y-m-d H:i:s")]);
  981. ProcessOrder::AddProcess($this->post['token'], [
  982. "order_type" => 'SPSX',
  983. "order_code" =>$online['skuCode'],//咨询单详情编号
  984. "order_id" => $online['id'],
  985. "order_status" => 2,
  986. "before_status"=>$online['exam_status'],
  987. 'holder_id' => $online['createrid'],
  988. ]);
  989. }
  990. }
  991. // if ($status == 1) {
  992. // //把同一个spuCode,且状态为1待完善成本,的记录更改状态为2待产品审核
  993. // Db::name('good')
  994. // ->where(['is_del' => 0, 'status' => 1])
  995. // ->whereIn('spuCode', $supcode)
  996. // ->update(['status' => 2, 'updatetime' => date('Y-m-d H:i:s')]);
  997. // }
  998. $old_status = $data['status'];
  999. $data['status']=$status;
  1000. $data['updatetime']=date("Y-m-d H:i:s");
  1001. $up= Db::name("good_basic")->save($data);
  1002. if($up){
  1003. //修改状态,添加待办
  1004. ActionLog::logAdd($this->post['token'], [
  1005. "order_code" =>$supcode,//咨询单详情编号
  1006. "status" => $status,//这里的status是之前的值
  1007. "action_remark" => '',//备注
  1008. "action_type" => "edit"//新建create,编辑edit,更改状态status
  1009. ], "SPCB",$data['status'] ,$data);
  1010. ProcessOrder::AddProcess($this->post['token'], [
  1011. "order_type" => 'SPCB',
  1012. "order_code" => $supcode,//咨询单详情编号
  1013. "order_id" => $data['id'],
  1014. "order_status" =>$data['status'],
  1015. "before_status"=>$old_status,
  1016. 'holder_id'=>$data['createrid'],
  1017. ]);
  1018. $data=[
  1019. "code"=>$supcode,
  1020. "exam_status"=>$status,
  1021. "type"=>1,
  1022. "exam_id"=>$createrid,
  1023. "exam_name"=>$creater,
  1024. "exam_remark"=>$remark,
  1025. "addtime"=>date("Y-m-d H:i:s")
  1026. ];
  1027. $inr=Db::name("good_exam")->insert($data);
  1028. if($inr){
  1029. Db::commit();
  1030. return app_show(0,"审核成功");
  1031. }else{
  1032. Db::rollback();
  1033. return error_show(1004,"审核失败");
  1034. }
  1035. }else{
  1036. Db::rollback();
  1037. return error_show(1004,"审核失败");
  1038. }
  1039. }catch (\Exception $e){
  1040. Db::rollback();
  1041. return error_show(1004,$e->getMessage());
  1042. }
  1043. }
  1044. public function info(){
  1045. $supcode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):"";
  1046. if($supcode==""){
  1047. return error_show(1004,"参数spuCode不能为空");
  1048. }
  1049. $data = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->find();
  1050. if($data==false){
  1051. return error_show(1004,"未找到商品数据");
  1052. }
  1053. $unit =Db::name("unit")->where(["id"=>$data['good_unit']])->find();
  1054. $data['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1055. $data['cat_info'] = made($data['cat_id'],[]);
  1056. $spec = Db::name("good_spec")->where(["spuCode"=>$supcode,"is_del"=>0])->select()->toArray();
  1057. // $supplier = Db::name("supplier")->where(["code"=>$data['supplierNo']])->find();
  1058. // $data['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  1059. $supplier = Db::name("supplier")->where(["code"=>$data['supplierNo']])->find();
  1060. $data['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  1061. $company = Db::name("business")->where(["companyNo"=>$data['companyNo']])->find();
  1062. $data['company'] = isset($company['company'])?$company['company']:"";
  1063. $data['field_change'] = $data['field_change']!=''?json_decode($data['field_change']):"";
  1064. if($data['brand_id']!=0){
  1065. $brand=Db::name("brand")->where(["id"=>$data['brand_id']])->find();
  1066. $data["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1067. }else{
  1068. $data["brand_name"]="";
  1069. $data["brand_id"]="";
  1070. }
  1071. $excluse = makeExcluse($data['is_exclusive']);
  1072. $data['exclusive']=$excluse;
  1073. $data['noble_name']=isset($data['noble_metal'])&&$data['noble_metal']!=0?$this->noble[$data['noble_metal']] :"";
  1074. $data["good_info_img"]=$data['good_info_img']!=""? $data['good_info_img']:'';
  1075. $data["good_img"]=$data['good_img']!=""? $data['good_img']:[];
  1076. $gold=[];
  1077. if ($data['is_gold_price'] == 1) {
  1078. $gold = Db::name("gold_price1")->where(["type" => $data['noble_metal'], "status" => 1, "is_del" => 0])->order("addtime desc")->find();
  1079. }
  1080. $data['gold_price'] =isset($gold["price"])?$gold["price"]:0;
  1081. $speclist=[];
  1082. if(!empty($spec)){
  1083. foreach ($spec as $value){
  1084. $temp=[];
  1085. $temp['id']=$value['id'];
  1086. $temp['spuCode']=$value['spuCode'];
  1087. $temp['spec_id']=$value['spec_id'];
  1088. $temp['spec_value_id']=$value['spec_value_id'];
  1089. $temp['is_del']=$value['is_del'];
  1090. $sp = Db::name("specs")->where(["id"=>$value['spec_id']])->find();
  1091. $temp['spec_name']=isset($sp["spec_name"]) ? $sp["spec_name"]:"";
  1092. $spv = Db::name("spec_value")->where(["id"=>$value['spec_value_id']])->find();
  1093. $temp['spec_value']=isset($spv["spec_value"]) ? $spv["spec_value"]:"";
  1094. $speclist[]=$temp;
  1095. }
  1096. }
  1097. $data["speclist"]=empty($speclist)?[]:$speclist;
  1098. // $nake=[];
  1099. $nakelist = Db::name("good_nake")->where(['spuCode'=>$supcode,"is_del"=>0])->select()->toArray();
  1100. // $catinfo = Db::name("cat")->where(["id"=>$data['cat_id']])->find();
  1101. // $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  1102. $nakearry=[];
  1103. if(!empty($nakelist)){
  1104. foreach ($nakelist as $value) {
  1105. $nakearry[] = $value;
  1106. }
  1107. }
  1108. $data["nakelist"]=$nakearry;
  1109. $data['cgderid'] = $supplier['personid'] ?? '';
  1110. $data['cgder'] = $supplier['person'] ?? '';
  1111. return app_show(0,"获取成功",$data);
  1112. }
  1113. //删除商品成本
  1114. public function delall()
  1115. {
  1116. // $supcode = isset($this->post['codes'])&&!empty($this->post['codes'])? $this->post['codes']:"";
  1117. $supcode = $this->request->post('codes', '', 'trim');
  1118. if ($supcode == "") {
  1119. return error_show(1004, "参数codes不能为空");
  1120. }
  1121. Db::startTrans();
  1122. try {
  1123. $good_basic = Db::name("good_basic")
  1124. ->field('id,spuCode,status')
  1125. ->where(["spuCode" => $supcode, "is_del" => 0])
  1126. ->select()->toArray();
  1127. if (empty($good_basic)) throw new Exception('该记录不存在或已删除');
  1128. $good = Db::name('good')
  1129. ->alias('g')
  1130. ->field('gp.id,gp.exam_status,gp.skuCode')
  1131. ->leftJoin('good_platform gp', 'gp.spuCode=g.spuCode AND gp.is_del=0')
  1132. ->where(['g.spuCode' => $supcode, 'g.is_del' => 0])
  1133. ->whereNotIn('gp.exam_status', [1, 8])
  1134. ->select()->toArray();
  1135. if (!empty($good)) throw new Exception('该商品需要下线之后才能删除');
  1136. Db::name("good_basic")
  1137. ->where(["spuCode" => $supcode, 'is_del' => 0])
  1138. ->update(['is_del' => 1, 'updatetime' => date('Y-m-d H:i:s')]);
  1139. Db::name("good")
  1140. ->where(['spuCode' => $supcode, 'is_del' => 0])
  1141. ->update(['is_del' => 1, 'updatetime' => date('Y-m-d H:i:s')]);
  1142. Db::name("good_platform")
  1143. ->where(['spuCode' => $supcode, 'is_del' => 0])
  1144. ->whereIn('exam_status', [1, 8])
  1145. ->update(['is_del' => 1, 'updatetime' => date('Y-m-d H:i:s')]);
  1146. Db::name("good_ladder")->where(["skuCode"=>array_column($good,"skuCode"),"is_del"=>0])->update(['is_del'
  1147. => 1, 'updatetime' => date('Y-m-d H:i:s')]);
  1148. Db::name("good_nake")->where(["spuCode"=>$supcode,"is_del"=>0])->update(['is_del'
  1149. => 1, 'updatetime' => date('Y-m-d H:i:s')]);
  1150. ProcessOrder::workdel(["order_type" => "SPCB", "order_code" => $supcode]);
  1151. ProcessOrder::workdel(["order_type" => "SPSX", "order_code" => array_column($good,"skuCode")]);
  1152. Db::commit();
  1153. app_show(0, "删除成功");
  1154. } catch (Exception $exception) {
  1155. Db::rollback();
  1156. return error_show(1005, "删除失败," . $exception->getMessage());
  1157. }
  1158. // $data = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->select()->toArray();
  1159. // if(empty($data)){
  1160. // return error_show(1004,"未找到商品数据");
  1161. // }
  1162. // $up= Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->save(["is_del"=>1]);
  1163. // if($up){
  1164. // ProcessOrder::workdel(["order_type"=>"CGD","order_code"=>$supcode]);
  1165. // return app_show(0,"更新成功");
  1166. // }else{
  1167. // return error_show(1005,"更新失败");
  1168. // }
  1169. }
  1170. //添加上线商品
  1171. public function online(){
  1172. $platform =isset($this->post['platform'])&&!empty($this->post['platform'])? $this->post['platform']:"";
  1173. if($platform==""){
  1174. return error_show(1004,"参数platform不能为空");
  1175. }
  1176. $spuCode =isset($this->post['codes'])&&!empty($this->post['codes'])? $this->post['codes']:"";
  1177. if($spuCode===''){
  1178. return error_show(1004,"参数codes不能为空");
  1179. }
  1180. $datas = Db::name("good_basic")->where(["spuCode"=>$spuCode,"is_del"=>0])->select()->toArray();
  1181. if(empty($datas)){
  1182. return error_show(1004,"未找到商品数据");
  1183. }
  1184. $online_reason = isset($this->post['online_reason'])&&$this->post['online_reason']!==""? trim($this->post['online_reason']):"";
  1185. if($online_reason===""){
  1186. return error_show(1004,"参数online_reason不能为空");
  1187. }
  1188. $online_remark= isset($this->post['online_remark'])&&$this->post['online_remark']!==""? trim($this->post['online_remark']):"";
  1189. if($online_remark===""){
  1190. return error_show(1004,"参数online_remark不能为空");
  1191. }
  1192. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1193. if($token==''){
  1194. return error_show(105,"参数token不能为空");
  1195. }
  1196. $user =GetUserInfo($token);
  1197. if(empty($user)||$user['code']!=0){
  1198. return error_show(1002,"用户数据不存在");
  1199. }
  1200. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1201. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1202. //区分是否是对接平台
  1203. $platform_info=Db::name('platform')
  1204. ->field('id,platform_type')
  1205. ->where(['is_del'=>0,'id'=>$platform])
  1206. ->find();
  1207. if(empty($platform_info)) return error_show(1005,'所选的平台不存在');
  1208. if($platform_info['platform_type']==1) return \app\youzan\logic\Goodup::create([
  1209. 'platform_id'=>$platform,
  1210. 'online_reason'=>$online_reason,
  1211. 'online_remark'=>$online_remark,
  1212. 'good_data'=>$datas,
  1213. 'createrid'=>$createrid,
  1214. 'creater'=>$creater,
  1215. ]);
  1216. $data=[];
  1217. $isonline=[];
  1218. $i=0;
  1219. Db::startTrans();
  1220. try{
  1221. foreach ($datas as $value){
  1222. $count = Db::name("good_nake")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->count();
  1223. $ist =Db::name("good_platform")->where(["spuCode"=>$value['spuCode'],"platform_code"=>$platform,"is_del"=>0])->find();
  1224. if($ist){
  1225. $god=Db::name("good_basic")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->find();
  1226. if($god){
  1227. $tp=[];
  1228. $tp['spuCode']=$value['spuCode'];
  1229. $tp['good_name']=$god['good_name'];
  1230. $tp['good_img']=$god['good_thumb_img'];
  1231. $tp['exam_status']=$ist['exam_status'];
  1232. $spec = Db::name("good_spec")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->select()->toArray();
  1233. $speclist=[];
  1234. if(!empty($spec)){
  1235. foreach ($spec as $val){
  1236. $temp=[];
  1237. $temp['id']=$val['id'];
  1238. $temp['spuCode']=$val['spuCode'];
  1239. $temp['spec_id']=$val['spec_id'];
  1240. $temp['spec_value_id']=$val['spec_value_id'];
  1241. $temp['is_del']=$val['is_del'];
  1242. $sp = Db::name("specs")->where(["id"=>$val['spec_id']])->find();
  1243. $temp['spec_name']=isset($sp["spec_name"]) ? $sp["spec_name"]:"";
  1244. $spv = Db::name("spec_value")->where(["id"=>$val['spec_value_id']])->find();
  1245. $temp['spec_value']=isset($spv["spec_value"]) ? $spv["spec_value"]:"";
  1246. $speclist[]=$temp;
  1247. }
  1248. }
  1249. $tp["speclist"]=empty($speclist)?[]:$speclist;
  1250. $isonline[]=$tp;
  1251. }
  1252. }
  1253. if(!empty($isonline)){
  1254. return app_show(1009,"存在已上线产品",$isonline);
  1255. }
  1256. //改变编码规则,将原来的skuCode后两位换成序列号
  1257. //str_pad字符串填充
  1258. $skuCode = makeNo("SN");
  1259. $skuCode = substr($skuCode, 0, -2) . str_pad($i, 2, '0', STR_PAD_LEFT);
  1260. $tmp=[
  1261. "spuCode"=>$value['spuCode'],
  1262. "skuCode"=>$skuCode,
  1263. "platform_code"=>$platform,
  1264. "online_reason"=>$online_reason,
  1265. "online_remark"=>$online_remark,
  1266. "exam_status"=>$count>0 ?2:1,
  1267. "is_online"=>0,
  1268. "status"=>1,
  1269. "is_del"=>0,
  1270. "creater"=>$creater,
  1271. "createrid"=>$createrid,
  1272. "addtime"=>date("Y-m-d H:i:s"),
  1273. "updatetime"=>date("Y-m-d H:i:s")
  1274. ];
  1275. $i++;
  1276. //修改状态,添加待办
  1277. $create =Db::name("good_platform")->insert($tmp,true);
  1278. if($create>0){
  1279. ActionLog::logAdd($this->post['token'], [
  1280. "order_code" =>$skuCode,//咨询单详情编号
  1281. "status" => $tmp['exam_status'],//这里的status是之前的值
  1282. "action_remark" => '',//备注
  1283. "action_type" => "create"//新建create,编辑edit,更改状态status
  1284. ], "SPSX",$tmp['exam_status'],$tmp);
  1285. ProcessOrder::AddProcess($this->post['token'], [
  1286. "order_type" => 'SPSX',
  1287. "order_code" =>$skuCode,//咨询单详情编号
  1288. "order_id" => $create,
  1289. "order_status" =>$tmp['exam_status'],
  1290. "before_status"=>$tmp['exam_status'],
  1291. 'holder_id' => $tmp['createrid'],
  1292. ]);
  1293. $iso = Db::name("good")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->find();
  1294. if($iso==false){
  1295. unset($value['id']);
  1296. $value['addtime']=date("Y-m-d H:i:s");
  1297. $value['updatetime']=date("Y-m-d H:i:s");
  1298. }else{
  1299. $value['id']=$iso['id'];
  1300. $value['updatetime']=date("Y-m-d H:i:s");
  1301. }
  1302. $up = Db::name("good")->strict(false)->save($value);
  1303. if(!$up){
  1304. Db::rollback();
  1305. return error_show(1004,"提交失败");
  1306. }
  1307. }else{
  1308. Db::rollback();
  1309. return error_show(1004,"提交失败");
  1310. }
  1311. }
  1312. // if($create){
  1313. // foreach ($datas as $value){
  1314. // $iso = Db::name("good")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->find();
  1315. // if($iso==false){
  1316. // unset($value['id']);
  1317. // $value['creater']=$creater;
  1318. // $value['createrid']=$createrid;
  1319. // $value['addtime']=date("Y-m-d H:i:s");
  1320. // $value['updatetime']=date("Y-m-d H:i:s");
  1321. // }else{
  1322. // $value['id']=$iso['id'];
  1323. // $value['creater']=$creater;
  1324. // $value['createrid']=$createrid;
  1325. // $value['updatetime']=date("Y-m-d H:i:s");
  1326. // }
  1327. // $up =Db::name("good")->save($value);
  1328. // if(!$up){
  1329. // Db::rollback();
  1330. // return error_show(1004,"提交失败");
  1331. // }
  1332. //
  1333. // //添加审核记录
  1334. // //修改状态,添加待办
  1335. // $skuCodes = array_column($data, 'skuCode', 'spuCode');
  1336. //
  1337. // ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
  1338. // "order_code" => $skuCodes[$value['spuCode']],//编号
  1339. // "status" => 2,//待产品审核
  1340. // "action_remark" => '',//备注
  1341. // "action_type" => "create"//新建create,编辑edit,更改状态status
  1342. // ], "SPSX", $value['status'], $value);
  1343. //
  1344. // ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
  1345. // "order_type" => 'SPSX',
  1346. // "order_code" => $skuCodes[$value['spuCode']],//咨询单详情编号
  1347. // "order_id" => isset($value['id']) ? $value['id'] : 0,
  1348. // "order_status" => 2,//待产品审核
  1349. // ]);
  1350. // }
  1351. // Db::commit();
  1352. // return app_show(0,"提交成功");
  1353. // }else{
  1354. // Db::rollback();
  1355. // return error_show(1004,"提交失败");
  1356. // }
  1357. Db::commit();
  1358. return app_show(0,"提交成功");
  1359. }catch (\Exception $e){
  1360. Db::rollback();
  1361. return error_show(1004, $e->getMessage());
  1362. }
  1363. }
  1364. //审核
  1365. public function online_exam(){
  1366. $skuCode = isset($this->post['skuCode'])&&$this->post['skuCode']!==""?trim($this->post['skuCode']):"";
  1367. if($skuCode===""){
  1368. return error_show(1004,"参数skuCode不能为空");
  1369. }
  1370. $platform = Db::name("good_platform")->where(["skuCode"=>$skuCode,"is_del"=>0])->find();
  1371. if($platform==false){
  1372. return error_show(1004,"未找到数据");
  1373. }
  1374. $exam_status=isset($this->post['exam_status'])&&$this->post['exam_status']!==""?intval($this->post['exam_status']):"";
  1375. // if($exam_status===""){
  1376. // return error_show(1004,"参数exam_status不能为空");
  1377. // }
  1378. //下线
  1379. if ($exam_status == 8) {
  1380. $offline_reason = isset($this->post['offline_reason']) && $this->post['offline_reason'] !== "" ? trim($this->post['offline_reason']) : "";
  1381. if ($offline_reason == '') return error_show(1005, '商品下线时下线原因必填');
  1382. $offline_remark = isset($this->post['offline_remark']) && $this->post['offline_remark'] !== "" ? trim($this->post['offline_remark']) : "";
  1383. }
  1384. if($exam_status==3){
  1385. $online_time= isset($this->post['online_time'])&&$this->post['online_time']!==""?$this->post['online_time']:"";
  1386. if($online_time===""){
  1387. return error_show(1004,"参数online_time不能为空");
  1388. }
  1389. $platform['online_time']=$online_time;
  1390. }
  1391. if($exam_status==6){
  1392. $good_code= isset($this->post['plat_code'])&&$this->post['plat_code']!==""?trim($this->post['plat_code']):"";
  1393. if($good_code===""){
  1394. return error_show(1004,"参数plat_code不能为空");
  1395. }
  1396. // $issale=Db::name("sale")->where(["skuCode"=>$platform['skuCode'],"status"=>[0,1,2]])->find();
  1397. // if($issale!=false &&$platform['plat_code']!=$good_code){
  1398. // return error_show(1004,"商品已下单,平台商品编码不允许修改");
  1399. // }
  1400. $is_exit = Db::name("good_platform")
  1401. ->where(["plat_code" => $good_code, "platform_code" => $platform['platform_code'], "is_del" => 0, 'exam_status' => 6])//exam_status==6已上线
  1402. ->where("id", "<>", $platform['id'])
  1403. ->find();
  1404. if($is_exit==false){
  1405. $platform['plat_code']=$good_code;
  1406. }else{
  1407. return error_show(1004,"平台商品编码 {$good_code} 已存在");
  1408. }
  1409. }
  1410. $exam_remark = isset($this->post['exam_remark'])&&$this->post['exam_remark']!==""?trim($this->post['exam_remark']):"";
  1411. $bifore=$platform['exam_status'];
  1412. $platform['exam_status']=$exam_status;
  1413. $platform['updatetime']=date("Y-m-d H:i:s");
  1414. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1415. if($token==''){
  1416. return error_show(105,"参数token不能为空");
  1417. }
  1418. $user =GetUserInfo($token);
  1419. if(empty($user)||$user['code']!=0){
  1420. return error_show(1002,"用户数据不存在");
  1421. }
  1422. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1423. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1424. Db::startTrans();
  1425. try {
  1426. $up = Db::name("good_platform")->save($platform);
  1427. if($up){
  1428. $data=[
  1429. "code"=>$platform['skuCode'],
  1430. "exam_status"=>$bifore,//$exam_status,
  1431. "type"=>2,
  1432. "exam_id"=>$createrid,
  1433. "exam_name"=>$creater,
  1434. "exam_remark"=>$exam_remark,
  1435. "addtime"=>date("Y-m-d H:i:s")
  1436. ];
  1437. $inr=Db::name("good_exam")->insert($data);
  1438. if($inr){
  1439. //如果是商品下线的话,记入商品下线记录表
  1440. if ($exam_status == 8) {
  1441. $offline_id = Db::name("good_offline_log")->insertGetId([
  1442. 'spuCode' => $platform['spuCode'],
  1443. 'skuCodes' => $skuCode,
  1444. 'good_name' => Db::name("good_basic")->where('spuCode', $platform['spuCode'])->value('good_name', ''),
  1445. 'offline_reason' => $offline_reason,
  1446. 'offline_remark' => $offline_remark,
  1447. 'createrid' => $createrid,
  1448. 'creater' => $creater,
  1449. 'addtime' => date('Y-m-d H:i:s'),
  1450. ]);
  1451. ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
  1452. "order_code" => $skuCode,//编号
  1453. "status" => $bifore,
  1454. "action_remark" => '',//备注
  1455. "action_type" => "status"//新建create,编辑edit,更改状态status
  1456. ], "GOL", $exam_status, $platform);
  1457. ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
  1458. "order_type" => 'GOL',
  1459. "order_code" => $skuCode,//咨询单详情编号
  1460. "order_id" => $offline_id,//商品下线记录的ID
  1461. "order_status" => $exam_status, "before_status" => $bifore
  1462. ]);
  1463. //根据权限查询应该接收商品下线通知的人员
  1464. $all_uid_name = Db::name('role_action')
  1465. ->whereFindInSet('action_conllect','877')//数据写死的,要注意各个环境数据是否一致
  1466. ->field('role_id')
  1467. ->buildSql();
  1468. $all_user = Db::name('user_role')
  1469. ->alias('ur')
  1470. ->where('ur.roleid IN '.$all_uid_name)
  1471. ->leftJoin('depart_user du','du.uid = ur.uid AND du.is_del=0')
  1472. ->column('ur.uid,du.nickName');
  1473. $insert_order_msg_data=[];
  1474. foreach ($all_user as $itemitem) {
  1475. $insert_order_msg_data[] = [
  1476. 'content' => '商品下线:' . $skuCode . '由' . $creater . '操作下线',
  1477. 'orderCode' => $skuCode,
  1478. 'order_type' => 'GOL',
  1479. 'order_status' => 8,
  1480. 'order_id' => $offline_id,
  1481. 'apply_id' => $createrid,
  1482. 'apply_name' => $creater,
  1483. 'uid' => $itemitem['uid'],
  1484. 'uname' => empty($itemitem['nickName']) ? '' : $itemitem['nickName'],
  1485. 'is_read' => 0,
  1486. 'addtime' => date('Y-m-d H:i:s'),
  1487. 'updatetime' => date('Y-m-d H:i:s'),
  1488. ];
  1489. }
  1490. //消息表
  1491. Db::name('order_msg')->insertAll($insert_order_msg_data);
  1492. }
  1493. ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
  1494. "order_code" => $skuCode,//编号
  1495. "status" => $bifore,
  1496. "action_remark" => '',//备注
  1497. "action_type" => "status"//新建create,编辑edit,更改状态status
  1498. ], "SPSX", $exam_status, $platform);
  1499. ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
  1500. "order_type" => 'SPSX',
  1501. "order_code" => $skuCode,//咨询单详情编号
  1502. "order_id" => $platform['id'],
  1503. "order_status" => $exam_status,
  1504. "before_status" => $bifore,
  1505. 'holder_id' => $platform['createrid'],
  1506. ]);
  1507. //商品上线的话,将数据包塞入到队列中
  1508. if ($exam_status == 6) {
  1509. //将上线成功数据塞入到队列中
  1510. $good_info = Db::name('good_basic')
  1511. ->field('id,good_name,supplierNo')
  1512. ->where(['is_del' => 0, 'spuCode' => $platform['spuCode']])
  1513. ->findOrEmpty();
  1514. if ($good_info) {
  1515. $push_data = json_encode([
  1516. 'supplierNo' => $good_info['supplierNo'],
  1517. 'type' => 2,//1销售订单(采销的采购单),2上线结果
  1518. 'data' => [
  1519. 'spuCode' => $platform['spuCode'],
  1520. 'skuCode' => $platform['skuCode'],
  1521. 'good_name' => $good_info['good_name'],
  1522. 'platform_id' => $platform['platform_code'],
  1523. 'platform_name' => Db::name('platform')->where(['id' => $platform['platform_code']])->value('platform_name', ''),
  1524. 'plat_code' => $platform['plat_code'],
  1525. 'online_time' => $platform['online_time'],
  1526. ],
  1527. ], JSON_UNESCAPED_UNICODE);
  1528. Cache::store("redis")->handler()->lPush(Config::get('app.abutment_queue'), $push_data);
  1529. }
  1530. }
  1531. Db::commit();
  1532. return app_show(0,"审核成功");
  1533. }else{
  1534. Db::rollback();
  1535. return error_show(1004,"审核失败");
  1536. }
  1537. }else{
  1538. Db::rollback();
  1539. return error_show(1004,"审核失败");
  1540. }
  1541. }catch (\Exception $e){
  1542. Db::rollback();
  1543. return error_show(1004,$e->getMessage());
  1544. }
  1545. }
  1546. //财务定价
  1547. public function editladder(){
  1548. $skuCode = isset($this->post['skuCode'])&&$this->post['skuCode']!==""?trim($this->post['skuCode']):"";
  1549. if($skuCode===""){
  1550. return error_show(1004,"参数skuCode不能为空");
  1551. }
  1552. $platform = Db::name("good_platform")->where(["skuCode"=>$skuCode,"is_del"=>0])->find();
  1553. if($platform==false){
  1554. return error_show(1004,"未找到数据");
  1555. }
  1556. $good_ladder = isset($this->post['good_ladder'])&&!empty($this->post['good_ladder'])?$this->post['good_ladder']:"";
  1557. if($good_ladder==""){
  1558. return error_show(1004,"参数good_ladder不能为空");
  1559. }
  1560. $proof_type = isset($this->post['proof_type'])&&$this->post['proof_type']!==""?intval($this->post['proof_type']):"";
  1561. if($proof_type===""){
  1562. return error_show(1004,"参数proof_type不能为空");
  1563. }
  1564. $proof_url = isset($this->post['proof_url'])&&$this->post['proof_url']!==""?trim($this->post['proof_url']):"";
  1565. if($proof_url===""){
  1566. return error_show(1004,"参数proof_url不能为空");
  1567. }
  1568. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1569. if($token==''){
  1570. return error_show(105,"参数token不能为空");
  1571. }
  1572. $exam_remark = isset($this->post['exam_remark'])&& $this->post['exam_remark']!='' ? trim($this->post['exam_remark']):"";
  1573. $user =GetUserInfo($token);
  1574. if(empty($user)||$user['code']!=0){
  1575. return error_show(1002,"用户数据不存在");
  1576. }
  1577. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1578. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1579. $bifore=$platform['exam_status'];
  1580. $platform['exam_status']=4;
  1581. $platform['updatetime']=date("Y-m-d H:i:s");
  1582. Db::startTrans();
  1583. try {
  1584. foreach ($good_ladder as $value){
  1585. $lemp=[];
  1586. isset($value["id"])&&$value["id"]!=""?$lemp['id']=$value['id']:"";
  1587. $lemp['skuCode']=$skuCode;
  1588. $lemp['min_num'] = $value['min_num'];
  1589. $lemp['max_num'] = 0;
  1590. $lemp['sale_price'] = $value['sale_price'];
  1591. $lemp['market_price'] = $value['market_price'];
  1592. $lemp['market_platform'] = $value['market_platform'];
  1593. $lemp['cost_fee'] = $value['cost_fee'];
  1594. $lemp['status'] = $value['status'];
  1595. $lemp['is_del'] = isset($value['is_del'])?$value['is_del']:0;
  1596. isset($value["id"])&&$value["id"]!=""?"": $lemp['addtime'] = date("Y-m-d H:i:s");
  1597. $lemp['updatetime'] =date("Y-m-d H:i:s");
  1598. $count = Db::name("good_ladder")->save($lemp);
  1599. if($count==false){
  1600. Db::rollback();
  1601. return app_show(1004,"商品起订价修改失败");
  1602. }
  1603. }
  1604. $up = Db::name("good_platform")->save($platform);
  1605. if($up){
  1606. ActionLog::logAdd($this->post['token'], [
  1607. "order_code" =>$platform['skuCode'],//咨询单详情编号
  1608. "status" =>$bifore,//这里的status是之前的值
  1609. "action_remark" => '',//备注
  1610. "action_type" => "edit"//新建create,编辑edit,更改状态status
  1611. ], "SPSX", $platform['exam_status'],$platform);
  1612. ProcessOrder::AddProcess($this->post['token'], [
  1613. "order_type" => 'SPSX',
  1614. "order_code" =>$platform['skuCode'],//咨询单详情编号
  1615. "order_id" => $platform['id'],
  1616. "order_status" => $platform['exam_status'],
  1617. "before_status"=>$bifore,
  1618. 'holder_id' => $platform['createrid'],
  1619. ]);
  1620. $proof=[
  1621. 'spuCode'=>$platform['spuCode'],
  1622. 'proof_type'=>$proof_type,
  1623. 'proof_url'=>$proof_url,
  1624. 'is_del'=>0,
  1625. "creater"=>$creater,
  1626. "createrid"=>$createrid,
  1627. "addtime"=>date("Y-m-d H:i:s"),
  1628. "updatetime"=>date("Y-m-d H:i:s")
  1629. ];
  1630. $inproof = Db::name("good_proof")->insert($proof);
  1631. if($inproof==false){
  1632. Db::rollback();
  1633. return app_show(1004,"商品凭证新建失败");
  1634. }
  1635. $data=[
  1636. "code"=>$platform['skuCode'],
  1637. "type"=>2,
  1638. "exam_status"=>$bifore,//4,
  1639. "exam_id"=>$createrid,
  1640. "exam_name"=>$creater,
  1641. "exam_remark"=>$exam_remark,
  1642. "addtime"=>date("Y-m-d H:i:s")
  1643. ];
  1644. $inr=Db::name("good_exam")->insert($data);
  1645. if($inr){
  1646. Db::commit();
  1647. return app_show(0,"审核成功");
  1648. }else{
  1649. Db::rollback();
  1650. return error_show(1004,"审核失败");
  1651. }
  1652. }else{
  1653. Db::rollback();
  1654. return error_show(1004,"审核失败");
  1655. }
  1656. }catch (\Exception $e){
  1657. Db::rollback();
  1658. return error_show(1004,$e->getMessage());
  1659. }
  1660. }
  1661. public function prooflist(){
  1662. $page = isset($this->post['page']) && $this->post['page'] !==""? intval($this->post['page']):"1";
  1663. $size = isset($this->post['size']) && $this->post['size'] !==""? intval($this->post['size']):"10";
  1664. $where =[["is_del","=",0]];
  1665. $spuCode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):"";
  1666. if($spuCode!==""){
  1667. $where[]=["spuCode","like","%$spuCode%"];
  1668. }
  1669. $count = Db::name("good_proof")->where($where)->count();
  1670. $total = ceil($count / $size);
  1671. $page = $page >= $total ? $total : $page;
  1672. $data = Db::name("good_proof")->where($where)->page($page,$size)->order("addtime desc")->select();
  1673. return app_show(0,"获取成功",['list'=>$data,"count"=>$count]);
  1674. }
  1675. /**
  1676. * 已下线商品重新发起上线流程
  1677. */
  1678. public function againOnline(){
  1679. $skuCode = isset($this->post['skuCode'])&&$this->post['skuCode']!==""?trim($this->post['skuCode']):"";
  1680. if($skuCode===""){
  1681. return error_show(1004,"参数skuCode不能为空");
  1682. }
  1683. $platform = Db::name("good_platform")->where(["skuCode"=>$skuCode,"is_del"=>0])->find();
  1684. if($platform==false){
  1685. return error_show(1004,"未找到数据");
  1686. }
  1687. if($platform["exam_status"]!=7&&$platform["exam_status"]!=8){
  1688. return error_show(1004,"商品状态有误");
  1689. }
  1690. //判断平台商品编码是否重复
  1691. // $rs = Db::name("good_platform")
  1692. // ->field('id')
  1693. // ->where(["plat_code" => $platform['plat_code'],"platform_code" => $platform['platform_code'], 'exam_status' => 6, "is_del" => 0])//exam_status==6已上线
  1694. // ->where('id', '<>', $platform['id'])
  1695. // ->find();
  1696. // if (!empty($rs)) return error_show(1005, '该商品的平台商品编码已被使用');
  1697. $nake =Db::name("good_nake")->where(["spuCode"=>$platform['spuCode'],"is_del"=>0])->select()->toArray();
  1698. $bifore=$platform['exam_status'];
  1699. $platform['exam_status'] = empty($nake)?1:2;
  1700. $platform['updatetime'] = date("Y-m-d H:i:s");
  1701. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1702. if($token==''){
  1703. return error_show(105,"参数token不能为空");
  1704. }
  1705. $user =GetUserInfo($token);
  1706. if(empty($user)||$user['code']!=0){
  1707. return error_show(1002,"用户数据不存在");
  1708. }
  1709. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1710. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1711. Db::startTrans();
  1712. try {
  1713. $save =Db::name("good_platform")->save($platform);
  1714. if($save){
  1715. ActionLog::logAdd(['id'=>$createrid,'nickname'=>$creater], [
  1716. "order_code" =>$platform['skuCode'],//咨询单详情编号
  1717. "status" =>$bifore,//这里的status是之前的值
  1718. "action_remark" => '',//备注
  1719. "action_type" => "edit"//新建create,编辑edit,更改状态status
  1720. ], "SPSX", $platform['exam_status'],$platform);
  1721. ProcessOrder::AddProcess(['id'=>$createrid,'nickname'=>$creater], [
  1722. "order_type" => 'SPSX',
  1723. "order_code" =>$platform['skuCode'],//咨询单详情编号
  1724. "order_id" => $platform['id'],
  1725. "order_status" => $platform['exam_status'],
  1726. "before_status"=>$bifore,
  1727. 'holder_id' => $platform['createrid'],
  1728. ]);
  1729. $data=[
  1730. "code"=>$platform['skuCode'],
  1731. "type"=>2,
  1732. "exam_status"=>$bifore,//$platform['exam_status'] ,
  1733. "exam_id"=>$createrid,
  1734. "exam_name"=>$creater,
  1735. "exam_remark"=>'',
  1736. "addtime"=>date("Y-m-d H:i:s")
  1737. ];
  1738. $inr=Db::name("good_exam")->insert($data);
  1739. if($inr){
  1740. //将good_basic数据同步到good表
  1741. $good_basic = Db::name('good_basic')
  1742. ->where(['spuCode' => $platform['spuCode'], 'is_del' => 0])
  1743. ->find();
  1744. if (!empty($good_basic)) {
  1745. unset($good_basic['id']);
  1746. unset($good_basic['addtime']);
  1747. $good_basic['updatetime'] = date('Y-m-d H:i:s');
  1748. Db::name('good')
  1749. ->strict(false)
  1750. ->where(['spuCode' => $platform['spuCode'], 'is_del' => 0])
  1751. ->update($good_basic);
  1752. }
  1753. Db::commit();
  1754. return app_show(0,"审核成功");
  1755. }
  1756. }
  1757. Db::rollback();
  1758. return error_show(1004,"审核失败");
  1759. }catch (\Exception $e){
  1760. Db::rollback();
  1761. return error_show(1004,$e->getMessage());
  1762. }
  1763. }
  1764. public function copy(){
  1765. $supcode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):"";
  1766. if($supcode==""){
  1767. return error_show(1004,"参数spuCode不能为空");
  1768. }
  1769. $data = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->find();
  1770. if($data==false){
  1771. return error_show(1004,"未找到商品数据");
  1772. }
  1773. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1774. if($token==''){
  1775. return error_show(105,"参数token不能为空");
  1776. }
  1777. // $user =GetUserInfo($token);
  1778. // if(empty($user)||$user['code']!=0){
  1779. // return error_show(102,"用户数据不存在");
  1780. // }
  1781. $createrid= $this->uid;
  1782. $creater= $this->uname;
  1783. $nake = Db::name("good_nake")->where(["spuCode"=>$supcode,"is_del"=>0])->select()->toArray();
  1784. $ladd=[];
  1785. $newCode =makeNo("SKU");
  1786. if(!empty($nake)){
  1787. foreach ($nake as $value){
  1788. $tmp=[];
  1789. $tmp['spuCode']=$newCode;
  1790. $tmp['min_num']=$value['min_num'];
  1791. $tmp['nake_fee'] = $value['nake_fee'];
  1792. $tmp['cost_fee'] = $value['cost_fee'];
  1793. $tmp['delivery_fee'] = $value['delivery_fee'];
  1794. $tmp['cert_fee'] = $value['cert_fee'];
  1795. $tmp['mark_fee'] = $value['mark_fee'];
  1796. $tmp['package_fee'] = $value['package_fee'];
  1797. $tmp['other_fee'] = $value['other_fee'];
  1798. $tmp['nake_total'] =$value['nake_total'];
  1799. $tmp['creater_id']=$createrid;
  1800. $tmp['creater']=$creater;
  1801. $tmp['is_del']=$value['is_del'];
  1802. $tmp['addtime']=date("Y-m-d H:i:s");
  1803. $tmp['updatetime']=date("Y-m-d H:i:s");
  1804. $ladd[]=$tmp;
  1805. }
  1806. }
  1807. $spec = Db::name("good_spec")->where(["spuCode"=>$supcode,"is_del"=>0])->select()->toArray();
  1808. $specArr=[];
  1809. if(!empty($spec)){
  1810. foreach ($spec as $value){
  1811. $tmp=[];
  1812. $tmp['spuCode']=$newCode;
  1813. $tmp['spec_id']=$value['spec_id'];
  1814. $tmp['spec_value_id']=$value['spec_value_id'];
  1815. $tmp['is_del']=$value['is_del'];
  1816. $tmp['addtime']=date("Y-m-d H:i:s");
  1817. $tmp['updatetime']=date("Y-m-d H:i:s");
  1818. $specArr[]=$tmp;
  1819. }
  1820. }
  1821. Db::startTrans();
  1822. try {
  1823. unset($data['id']);
  1824. $data['spuCode']=$newCode;
  1825. $data['createrid']=$createrid;
  1826. $data['creater']=$creater;
  1827. $data['status']=7;
  1828. $data['addtime']=date("Y-m-d H:i:s");
  1829. $data['updatetime']=date("Y-m-d H:i:s");
  1830. $cre = Db::name("good_basic")->insertGetId($data);
  1831. if($cre){
  1832. //修改状态,添加待办
  1833. ActionLog::logAdd($this->post['token'], [
  1834. "order_code" =>$newCode,//咨询单详情编号
  1835. "status" => 0,//这里的status是之前的值
  1836. "action_remark" => '',//备注
  1837. "action_type" => "create"//新建create,编辑edit,更改状态status
  1838. ], "SPCB", 7,$data);
  1839. ProcessOrder::AddProcess($this->post['token'], [
  1840. "order_type" => 'SPCB',
  1841. "order_code" =>$newCode,//咨询单详情编号
  1842. "order_id" => $cre,
  1843. "order_status" =>7,
  1844. "before_status"=>0,
  1845. 'holder_id'=>$data['createrid'],
  1846. ]);
  1847. if(!empty($ladd)){
  1848. $na = Db::name("good_nake")->insertAll($ladd);
  1849. if($na==0){
  1850. Db::rollback();
  1851. return error_show(1005,"成本数据复制失败");
  1852. }
  1853. }
  1854. if(!empty($specArr)){
  1855. $sp = Db::name("good_spec")->insertAll($specArr);
  1856. if($sp==0){
  1857. Db::rollback();
  1858. return error_show(1005,"规格数据复制失败");
  1859. }
  1860. }
  1861. Db::commit();
  1862. return app_show(0,"复制数据成功",["spuCode"=>$newCode]);
  1863. }else{
  1864. Db::rollback();
  1865. return error_show(1005,"数据复制失败");
  1866. }
  1867. }catch (\Exception $e){
  1868. Db::rollback();
  1869. return error_show(1004,$e->getMessage());
  1870. }
  1871. }
  1872. public function edit(){
  1873. $supcode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):"";
  1874. if($supcode==""){
  1875. return error_show(1004,"参数spuCode不能为空");
  1876. }
  1877. $data = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->find();
  1878. if($data==false){
  1879. return error_show(1004,"未找到商品数据");
  1880. }
  1881. $is_down = Db::name("good_platform")
  1882. ->where(["spuCode"=>$supcode,"is_del"=>0])
  1883. ->where("exam_status", "not in", [1, 8])//exam_status=1待完善成本,8已下线,除了这两个状态外其他状态都不允许编辑
  1884. ->find();
  1885. if($is_down!=false){
  1886. return error_show(1004,"存在未下线商品数据");
  1887. }
  1888. if ($data['status'] != 6 && $data['status'] != 7 && $data['status'] != 8) {
  1889. return error_show(1004,"商品状态有误");
  1890. }
  1891. $good_name= isset($this->post['good_name'])&&$this->post['good_name']!="" ? trim($this->post['good_name']):"";
  1892. if($good_name==""){
  1893. return error_show(1004,"商品名称不能为空");
  1894. }
  1895. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? intval($this->post['cat_id']):"";
  1896. if($cat_id==''){
  1897. return error_show(1004,"商品分类不能为空");
  1898. }
  1899. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"0";
  1900. // if($brandid==''){
  1901. // return error_show(1004,"商品品牌不能为空");
  1902. // }
  1903. $unit = isset($this->post['unit'])&&$this->post['unit']!=""? trim($this->post['unit']):"";
  1904. if($unit==''){
  1905. return error_show(1004,"商品单位不能为空");
  1906. }
  1907. $good_type = isset($this->post['good_type'])&&$this->post['good_type']!==""? intval($this->post['good_type']) :"";
  1908. if($good_type===''){
  1909. return error_show(1004,"参数good_type不能为空");
  1910. }
  1911. $moq=0;
  1912. $customized=0;
  1913. if($good_type==1){
  1914. $moq = isset($this->post['moq'])&&$this->post['moq']!==""? intval($this->post['moq']):"";
  1915. if($moq===''){
  1916. return error_show(1004,"定制商品起订量不能为空");
  1917. }
  1918. $customized = isset($this->post['customized'])&&$this->post['customized']!==""? intval($this->post['customized']):"";
  1919. if($customized===''){
  1920. return error_show(1004,"参数customized不能为空");
  1921. }
  1922. }
  1923. $is_exclusive = isset($this->post['is_exclusive'])&&$this->post['is_exclusive']!==""? intval($this->post['is_exclusive']):"";
  1924. if($is_exclusive===''){
  1925. return error_show(1004,"参数is_exclusive不能为空");
  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. $tax = isset($this->post['tax'])&&$this->post['tax']!==""? intval($this->post['tax']):"";
  1932. if($tax===''){
  1933. return error_show(1004,"参数tax不能为空");
  1934. }
  1935. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
  1936. if($supplierNo==''){
  1937. return error_show(1004,"参数supplierNo不能为空");
  1938. }
  1939. $supplier = Db::name("supplier")->field('id,personid,person')->where(["code" => $supplierNo])->findOrEmpty();
  1940. if (empty($supplier)) return error_show(1004, "供应商信息未找到");
  1941. $good_size = isset($this->post['good_size'])&&$this->post['good_size']!=""? trim($this->post['good_size']) :"";
  1942. if($good_size==''){
  1943. return error_show(1004,"参数good_size不能为空");
  1944. }
  1945. $company_id = isset($this->post['companyNo'])&&$this->post['companyNo']!=""? trim($this->post['companyNo']) :"";
  1946. if($company_id==''){
  1947. return error_show(1004,"参数companyNo不能为空");
  1948. }
  1949. $is_auth = isset($this->post['is_auth'])&&$this->post['is_auth']!==""? intval($this->post['is_auth']):"";
  1950. if($is_auth===''){
  1951. return error_show(1004,"参数is_auth不能为空");
  1952. }
  1953. $auth_img = isset($this->post['auth_img'])&&$this->post['auth_img']!=""? trim($this->post['auth_img']):"";
  1954. // if($auth_img==''){
  1955. // return error_show(1004,"商品不能为空");
  1956. // }
  1957. $after_sales = isset($this->post['after_sales'])&&$this->post['after_sales']!=""? trim($this->post['after_sales']):"";
  1958. if($after_sales==""){
  1959. return error_show(1004,"参数after_sales不能为空");
  1960. }
  1961. $craft_desc = isset($this->post['craft_desc'])&&$this->post['craft_desc']!=""? trim($this->post['craft_desc']):"";
  1962. $good_remark = isset($this->post['good_remark'])&&$this->post['good_remark']!=""? trim($this->post['good_remark']):"";
  1963. if($good_remark===""){
  1964. return error_show(1004,"参数good_remark不能为空");
  1965. }
  1966. $weight = isset($this->post['weight'])&&$this->post['weight']!==""? floatval($this->post['weight']):"";
  1967. if($weight===""){
  1968. return error_show(1004,"参数weight不能为空");
  1969. }
  1970. $packing_way = isset($this->post['packing_way'])&&$this->post['packing_way']!==""? trim($this->post['packing_way']):"";
  1971. if($packing_way===""){
  1972. return error_show(1004,"参数packing_way不能为空");
  1973. }
  1974. $packing_size = isset($this->post['packing_size'])&&$this->post['packing_size']!==""? trim($this->post['packing_size']):"";
  1975. if($packing_size===""){
  1976. return error_show(1004,"参数packing_size不能为空");
  1977. }
  1978. $packing_spec = isset($this->post['packing_spec'])&&$this->post['packing_spec']!==""? trim($this->post['packing_spec']):"";
  1979. if($packing_spec===""){
  1980. return error_show(1004,"参数packing_spec不能为空");
  1981. }
  1982. $packing_weight = isset($this->post['packing_weight'])&&$this->post['packing_weight']!==""? floatval($this->post['packing_weight']):"";
  1983. if($packing_weight===""){
  1984. return error_show(1004,"参数packing_weight不能为空");
  1985. }
  1986. $packing_list = isset($this->post['packing_list'])&&$this->post['packing_list']!==""? trim($this->post['packing_list']):"";
  1987. if($packing_list===""){
  1988. return error_show(1004,"参数packing_list不能为空");
  1989. }
  1990. $good_bar = isset($this->post['good_bar'])&&$this->post['good_bar']!==""? trim($this->post['good_bar']):"";
  1991. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  1992. if($supply_area===""){
  1993. return error_show(1004,"参数supply_area不能为空");
  1994. }
  1995. $delivery_place = isset($this->post['delivery_place'])&&$this->post['delivery_place']!==""? $this->post['delivery_place']:"";
  1996. if($delivery_place===""){
  1997. return error_show(1004,"参数delivery_place不能为空");
  1998. }
  1999. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!==""? $this->post['origin_place']:"";
  2000. if($origin_place===""){
  2001. return error_show(1004,"参数origin_place不能为空");
  2002. }
  2003. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!==""? intval($this->post['delivery_day']):"";
  2004. if($delivery_day===""){
  2005. return error_show(1004,"参数delivery_day不能为空");
  2006. }
  2007. $lead_time = isset($this->post['lead_time'])&&$this->post['lead_time']!==""? intval($this->post['lead_time'])
  2008. :"0";
  2009. // if($lead_time===""){
  2010. // return error_show(1004,"参数lead_time不能为空");
  2011. // }
  2012. $sample_day = isset($this->post['sample_day'])&&$this->post['sample_day']!==""? intval($this->post['sample_day']):"0";
  2013. // if($sample_day===""){
  2014. // return error_show(1004,"参数sample_day不能为空");
  2015. // }
  2016. $sample_fee = isset($this->post['sample_fee'])&&$this->post['sample_fee']!==""? floatval($this->post['sample_fee']):"0";
  2017. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""? trim($this->post['good_img']):"";
  2018. if($good_img===""){
  2019. return error_show(1004,"参数good_img不能为空");
  2020. }
  2021. $good_thumb_img = isset($this->post['good_thumb_img'])&&$this->post['good_thumb_img']!==""? trim($this->post['good_thumb_img']):"";
  2022. if($good_thumb_img===""){
  2023. return error_show(1004,"参数good_thumb_img不能为空");
  2024. }
  2025. $good_info_img = isset($this->post['good_info_img'])&&!empty($this->post['good_info_img'])? trim($this->post['good_info_img']):"";
  2026. if($good_info_img===""){
  2027. return error_show(1004,"参数good_info_img不能为空");
  2028. }
  2029. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!==""? floatval($this->post['cert_fee']):"0";
  2030. $packing_fee = isset($this->post['packing_fee'])&&$this->post['packing_fee']!==""? floatval($this->post['packing_fee']):"0";
  2031. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!==""? floatval($this->post['cost_fee']):"0";
  2032. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!==""? floatval($this->post['mark_fee']):"0";
  2033. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!==""? floatval($this->post['demo_fee']):"0";
  2034. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!==""? floatval($this->post['open_fee']):"0";
  2035. $noble_metal = isset($this->post['noble_metal'])&&$this->post['noble_metal']!==""? intval($this->post['noble_metal']):"0";
  2036. $noble_weight = isset($this->post['noble_weight'])&&$this->post['noble_weight']!==""? floatval($this->post['noble_weight']):"0";
  2037. $is_gold_price= isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!==""? intval($this->post['is_gold_price']):"0";
  2038. $market_price = isset($this->post['market_price'])&&$this->post['market_price']!==""? floatval($this->post['market_price']):"";
  2039. $cgd_gold_price = isset($this->post['cgd_gold_price'])&&$this->post['cgd_gold_price']!==""? floatval($this->post['cgd_gold_price']):"0";
  2040. if($market_price===""){
  2041. return error_show(1004,"参数market_price不能为空");
  2042. }
  2043. $nake_price = isset($this->post['nake_price'])&&$this->post['nake_price']!==""? floatval($this->post['nake_price']):"0";
  2044. $config = isset($this->post['config'])&&$this->post['config']!==""? trim($this->post['config']):"";
  2045. $other_config = isset($this->post['other_config'])&&$this->post['other_config']!==""? trim($this->post['other_config']):"";
  2046. $is_diff = isset($this->post['is_diff'])&&$this->post['is_diff']!==""? intval($this->post['is_diff']):"0";
  2047. $is_stock = isset($this->post['is_stock'])&&$this->post['is_stock']!==""? intval($this->post['is_stock']):"0";
  2048. $stock_moq = isset($this->post['stock_moq'])&&$this->post['stock_moq']!==""? intval($this->post['stock_moq']):"0";
  2049. if($is_stock==1 && $stock_moq ==0){
  2050. return error_show(1004,"库存品备库起订量不能为零");
  2051. }
  2052. // $is_step = isset($this->post['is_step'])&&$this->post['is_step']!==""? intval($this->post['is_step']):"";
  2053. // if($is_step===""){
  2054. // return error_show(1004,"参数is_step不能为空");
  2055. // }
  2056. $good_ladder = isset($this->post['good_ladder'])&&!empty($this->post['good_ladder'])? $this->post['good_ladder']:"";
  2057. // if($is_step==1 && $good_ladder==""){
  2058. // return error_show(1004,"启用阶梯,阶梯价不能为空");
  2059. // }
  2060. $speclist = isset($this->post['speclist'])&&!empty($this->post['speclist'])? $this->post['speclist']:"";
  2061. $is_support_barter = isset($this->post['is_support_barter']) && $this->post['is_support_barter'] !== "" ? intval($this->post['is_support_barter']) : 1;
  2062. Db::startTrans();
  2063. try {
  2064. $temp=[
  2065. "good_name"=>$good_name,
  2066. "cat_id"=>$cat_id,
  2067. 'brand_id'=>$brandid,
  2068. "good_unit"=>$unit,
  2069. "good_type"=>$good_type,
  2070. "companyNo"=>$company_id,
  2071. "moq"=>$moq,
  2072. "is_exclusive"=>$is_exclusive,
  2073. "customized"=>$customized,
  2074. "tax"=>$tax,
  2075. "supplierNo"=>$supplierNo,
  2076. "is_auth"=>$is_auth,
  2077. "good_size"=>$good_size,
  2078. "auth_img"=>$auth_img,
  2079. "after_sales"=>$after_sales,
  2080. "craft_desc"=>$craft_desc,
  2081. "good_remark"=>$good_remark,
  2082. "weight"=>$weight,
  2083. "packing_way"=>$packing_way,
  2084. "packing_size"=>$packing_size,
  2085. "packing_spec"=>$packing_spec,
  2086. "packing_list"=>$packing_list,
  2087. "packing_weight"=>$packing_weight,
  2088. "good_bar"=>$good_bar,
  2089. "supply_area"=>$supply_area,
  2090. "delivery_place"=>$delivery_place,
  2091. "origin_place"=>$origin_place,
  2092. "delivery_day"=>$delivery_day,
  2093. "lead_time"=>$lead_time,
  2094. "sample_day"=>$sample_day,
  2095. "sample_fee"=>$sample_fee,
  2096. "good_img"=>$good_img,
  2097. "good_thumb_img"=>$good_thumb_img,
  2098. "good_info_img"=>$good_info_img,
  2099. "cert_fee"=>$cert_fee,
  2100. "packing_fee"=>$packing_fee,
  2101. "is_diff"=>$is_diff,
  2102. "config"=>$config,
  2103. "other_config"=>$other_config,
  2104. "is_stock"=>$is_stock,
  2105. "cost_fee"=>$cost_fee,
  2106. "mark_fee"=>$mark_fee,
  2107. "demo_fee"=>$demo_fee,
  2108. "open_fee"=>$open_fee,
  2109. "noble_metal"=>$noble_metal,
  2110. "noble_weight"=>$noble_weight,
  2111. "is_gold_price"=>$is_gold_price,
  2112. "market_price"=>$market_price,
  2113. "nake_price"=>$nake_price,
  2114. "cgd_gold_price"=>$cgd_gold_price,
  2115. "is_step" => count($good_ladder) > 1 ? 1 : 0,
  2116. "stock_moq"=>$stock_moq,
  2117. "status"=>"0",
  2118. "updatetime"=>date("Y-m-d H:i:s"),
  2119. 'is_support_barter'=>$is_support_barter,
  2120. 'chargerid' => $supplier['personid'] ?? $this->uid,
  2121. 'charger' => $supplier['person'] ?? $this->uname,
  2122. ];
  2123. $field = array_diff_assoc($temp,$data);
  2124. $temp['field_change'] =empty($field)?"":json_encode(array_keys($field));
  2125. $up = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->save($temp);
  2126. $var = array_diff($temp,$data);
  2127. $json = json_encode($var,JSON_UNESCAPED_UNICODE);
  2128. $dat = json_encode($data,JSON_UNESCAPED_UNICODE);
  2129. if($up){
  2130. ChangeLog::logAdd(3,$data['spuCode'],$dat,$json,$this->post['token'],$this->post);
  2131. //修改状态,添加待办
  2132. ActionLog::logAdd($this->post['token'], [
  2133. "order_code" =>$supcode,//咨询单详情编号
  2134. "status" => $data['status'],//这里的status是之前的值
  2135. "action_remark" => '',//备注
  2136. "action_type" => "create"//新建create,编辑edit,更改状态status
  2137. ], "SPCB", 0,$temp);
  2138. ProcessOrder::AddProcess($this->post['token'], [
  2139. "order_type" => 'SPCB',
  2140. "order_code" =>$supcode,//咨询单详情编号
  2141. "order_id" => $data['id'],
  2142. "order_status" =>0,
  2143. "before_status"=>0,
  2144. 'holder_id'=>$data['createrid'],
  2145. ]);
  2146. if($speclist!=="" && !empty($speclist)){
  2147. foreach ($speclist as $value){
  2148. $lemp=[];
  2149. isset($value["id"])&&$value["id"]!=''?$lemp['id']=$value['id']:"";
  2150. $lemp['spuCode']=$supcode;
  2151. $lemp['spec_id'] = $value['spec_id'];
  2152. $lemp['spec_value_id'] = $value['spec_value_id'];
  2153. $lemp['is_del'] = isset($value['is_del'])?$value['is_del']:0;
  2154. isset($value["id"])&&$value["id"]!=''?"": $lemp['addtime'] = date("Y-m-d H:i:s");
  2155. $lemp['updatetime'] =date("Y-m-d H:i:s");
  2156. $count = Db::name("good_spec")->save($lemp);
  2157. if($count==false){
  2158. Db::rollback();
  2159. return app_show(1004,"商品规格值修改失败");
  2160. }
  2161. }
  2162. }
  2163. if($good_ladder!=="" && !empty($good_ladder)){
  2164. $user =GetUserInfo($this->post['token']);//获取用户信息,下面更新成本表的创建人
  2165. $top_cat_id = made($cat_id);//获取所有分类
  2166. $top_cat_id = isset($top_cat_id[0]['id']) ? $top_cat_id[0]['id'] : 0;//获取顶级分类id
  2167. foreach ($good_ladder as $value){
  2168. $lemp=[];
  2169. isset($value["id"])&&$value["id"]!=''?$lemp['id']=$value['id']:"";
  2170. $lemp['spuCode']=$supcode;
  2171. $lemp['min_num'] = $value['min_num'];
  2172. $lemp['nake_fee'] = $value['nake_fee'];
  2173. $lemp['cost_fee'] = $value['cost_fee'];
  2174. $lemp['delivery_fee'] = $value['delivery_fee'];
  2175. $lemp['cert_fee'] = $value['cert_fee'];
  2176. $lemp['mark_fee'] = $value['mark_fee'];
  2177. $lemp['package_fee'] = $value['package_fee'];
  2178. $lemp['other_fee'] = $value['other_fee'];
  2179. if ($is_gold_price == 1 && $top_cat_id == 6) {
  2180. $gold =Db::name("gold_price1")->where(["type"=>$noble_metal,"status"=>1,"is_del"=>0])->order("addtime desc")->find();
  2181. //$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'];
  2182. //成本合计=贵金属重量*供应商采购金价 + 工艺费*贵金属重量+加标费+包装费+证书费+成本裸价+运费+其他费用
  2183. //成本总计启用实时金价时,采用供应商实时金价
  2184. $lemp['nake_total'] =$noble_weight *$gold['price']+ $value['cost_fee'] * $noble_weight +
  2185. $value['mark_fee'] + $value['package_fee'] + $value['cert_fee'] + $value['nake_fee'] + $value['delivery_fee'] + $value['other_fee'];
  2186. }else{
  2187. $lemp['nake_total'] =$value['nake_fee']+$value['delivery_fee']+$value['cert_fee']+$value['mark_fee']+$value['package_fee']+$value['other_fee'];
  2188. }
  2189. $lemp['creater_id'] = isset($user["data"]['id']) ? $user["data"]['id'] : 0;
  2190. $lemp['creater'] = isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  2191. $lemp['is_del'] = isset($value['is_del'])?$value['is_del']:0;
  2192. isset($value["id"])&&$value["id"]!=''?"": $lemp['addtime'] = date("Y-m-d H:i:s");
  2193. $lemp['updatetime'] =date("Y-m-d H:i:s");
  2194. $count = Db::name("good_nake")->save($lemp);
  2195. if($count==false){
  2196. Db::rollback();
  2197. return app_show(1004,"商品规成本修改失败");
  2198. }
  2199. }
  2200. }
  2201. Db::commit();
  2202. return app_show(0,"更新成功");
  2203. }else{
  2204. Db::rollback();
  2205. return error_show(1005,"更新失败");
  2206. }
  2207. }catch (\Exception $e){
  2208. Db::rollback();
  2209. return error_show(1004,$e->getMessage());
  2210. }
  2211. }
  2212. public function checkPrice(){
  2213. $spuCode=isset($this->post['spuCode'])&&$this->post['spuCode']!=""? trim($this->post['spuCode']):"";
  2214. if($spuCode==""){
  2215. return error_show(1005,"参数spuCode不能为空");
  2216. }
  2217. $good =Db::name("good_basic")->where(["spuCode"=>$spuCode,"is_del"=>0])->find();
  2218. if($good==false){
  2219. return error_show(1005,"商品数据未找到");
  2220. }
  2221. $num=isset($this->post['min_num'])&&$this->post['min_num']!=="" ? intval($this->post['min_num']):"";
  2222. if($num==""){
  2223. return error_show(1005,"参数min_num不能为空");
  2224. }
  2225. $nakelist = Db::name("good_nake")
  2226. ->where(['spuCode'=>$spuCode,"is_del"=>0])
  2227. ->where([["min_num","<=",$num]])
  2228. ->order("min_num desc")
  2229. ->find();
  2230. if($nakelist==false){
  2231. $nakelist = Db::name("good_nake")->where(['spuCode'=>$spuCode,"is_del"=>0])->order("min_num asc")->find();
  2232. //非库存品的话,继续校验最小起订量
  2233. //库存品的话,不足采购起订量的时候,取采购最小起订量
  2234. if ($good['is_stock'] == 0) return error_show(1010, "起订量不足{$nakelist['min_num']}");
  2235. }
  2236. $catinfo = Db::name("cat")->where(["id"=>$good['cat_id']])->find();
  2237. $budget = isset($catinfo['sale_rate']) ? $catinfo['sale_rate']/100:0;
  2238. $top_cat_id = made($catinfo['id']);//获取所有分类
  2239. $top_cat_id = isset($top_cat_id[0]['id']) ? $top_cat_id[0]['id'] : 0;//获取顶级分类id
  2240. $sale_cost_fee = 0;
  2241. if ($good['is_gold_price'] == 1 && $top_cat_id == 6) {
  2242. // $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'];
  2243. //系统售价=(贵金属重量*供应商采购金价 + 工艺费*贵金属重量+加标费+包装费+证书费+成本裸价+运费+其他费用)/(1-成本售价/100)
  2244. $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);
  2245. //计算工艺费
  2246. //销售工艺费=(( 商品重量* 供应商采购金价 + 采购成本工艺费* 商品重量+包装费+加标费+证书费+产品裸价+其他费用)/(1-成本售价/100)-(包装费+加标费+证书费+产品裸价0+运费+其他费用) )/商品重量-供应商采购金价
  2247. $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"];
  2248. }else{
  2249. // $saleprice = ($nakelist['mark_fee'] + $nakelist['package_fee'] + $nakelist['cert_fee'] + $nakelist['delivery_fee'] + $nakelist['nake_fee']) / (1 - $budget);
  2250. // (加标费+包装费+证书费+成本裸价+运费)/(1-成本售价/100)=系统售价
  2251. // $saleprice = (加标费 + 包装费 + 证书费 + 运费 + 成本裸价+其他费用) / (1 - $budget);
  2252. $saleprice = $nakelist['nake_total'] / (1 - $budget);
  2253. }
  2254. return app_show(0, "获取成功", ["sale_price" => round($saleprice, 2), 'new_cost_fee' => round($sale_cost_fee, 2)]);
  2255. }
  2256. //咨询成交商品池 添加上线商品
  2257. public function onlineZixunGoods()
  2258. {
  2259. $param = $this->request->only(['platform', 'codes', 'online_reason', 'online_remark', 'token'], 'post', 'trim');
  2260. $val = Validate::rule([
  2261. 'platform|所选上线平台' => 'require|number|gt:0',
  2262. 'codes|所选上线商品编号' => 'require',
  2263. 'online_reason|上线原因' => 'require',
  2264. 'online_remark|上线备注' => 'require',
  2265. 'token' => 'require',
  2266. ]);
  2267. if (!$val->check($param)) return error_show(1004, $val->getError());
  2268. $good_zixun_list = Db::name("good_zixun")
  2269. ->where(["is_del" => 0])
  2270. ->whereIn('spuCode', $param['codes'])
  2271. ->column('*', 'spuCode');
  2272. if (empty($good_zixun_list)) return error_show(1004, "未找到相关咨询商品数据");
  2273. $a = array_diff($param['codes'], array_keys($good_zixun_list));
  2274. if (!empty($a)) return error_show(1005, '该咨询商品不存在' . implode(',', $a));
  2275. $isonline = Db::name("good_platform")
  2276. ->alias('gp')
  2277. ->field('gp.id,gp.spuCode,gb.good_name,gb.good_img,gp.exam_status')
  2278. ->where(["gp.platform_code" => $param['platform'], "gp.is_del" => 0])
  2279. ->whereIn('gp.spuCode', $param['codes'])
  2280. ->leftJoin('good_basic gb', 'gb.spuCode=gp.spuCode AND gb.is_del=0')
  2281. ->select()
  2282. ->toArray();
  2283. if (!empty($isonline)) {
  2284. foreach ($isonline as &$v) {
  2285. $spec = Db::name("good_spec")
  2286. ->where(["spuCode" => $v['spuCode'], "is_del" => 0])
  2287. ->select()
  2288. ->toArray();
  2289. $speclist = [];
  2290. if (!empty($spec)) {
  2291. foreach ($spec as $val) {
  2292. $temp = [];
  2293. $temp['id'] = $val['id'];
  2294. $temp['spuCode'] = $val['spuCode'];
  2295. $temp['spec_id'] = $val['spec_id'];
  2296. $temp['spec_value_id'] = $val['spec_value_id'];
  2297. $temp['is_del'] = $val['is_del'];
  2298. $sp = Db::name("specs")->where(["id" => $val['spec_id']])->find();
  2299. $temp['spec_name'] = isset($sp["spec_name"]) ? $sp["spec_name"] : "";
  2300. $spv = Db::name("spec_value")->where(["id" => $val['spec_value_id']])->find();
  2301. $temp['spec_value'] = isset($spv["spec_value"]) ? $spv["spec_value"] : "";
  2302. $speclist[] = $temp;
  2303. }
  2304. }
  2305. $v["speclist"] = empty($speclist) ? [] : $speclist;
  2306. }
  2307. return app_show(1009, "存在已上线产品", $isonline);
  2308. }
  2309. if (!empty($isonline)) return error_show(1005, $isonline['spuCode'] . '该商品已在商品成本管理中,请在商品成本管理菜单提交上线!');
  2310. $user = GetUserInfo($param['token']);
  2311. if (empty($user) || $user['code'] != 0) return error_show(1002, "用户数据不存在");
  2312. $createrid = isset($user["data"]['id']) ? $user["data"]['id'] : "";
  2313. $creater = isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  2314. $data = $good_insert_data = $good_basic_insert_data = $good_spec_insert_data = [];
  2315. $i = 0;
  2316. $all_nakes = Db::name("good_nake")
  2317. ->where(["is_del" => 0])->fetchSql()
  2318. ->whereIn('spuCode', $param['codes'])
  2319. ->group('spuCode')
  2320. ->column('count(`id`) total', 'spuCode');
  2321. $all_good = Db::name('good')
  2322. ->where('is_del', 0)
  2323. ->whereIn('spuCode', $param['codes'])
  2324. ->column('id', 'spuCode');
  2325. if (!empty($all_good)) return error_show(1004, '请从商品成本提交该商品上线');
  2326. $all_good_basic = Db::name('good_basic')
  2327. ->where('is_del', 0)
  2328. ->whereIn('spuCode', $param['codes'])
  2329. ->column('id', 'spuCode');
  2330. if (!empty($all_good_basic)) return error_show(1004, '请从商品成本提交该商品上线');
  2331. foreach ($param['codes'] as $value) {
  2332. //改变编码规则,将原来的skuCode后两位换成序列号
  2333. //str_pad字符串填充
  2334. $skuCode = makeNo("SN");
  2335. $skuCode = substr($skuCode, 0, -2) . str_pad($i, 2, '0', STR_PAD_LEFT);
  2336. $data[] = [
  2337. "spuCode" => $value,
  2338. "skuCode" => $skuCode,
  2339. "platform_code" => $param['platform'],
  2340. "online_reason" => $param['online_reason'],
  2341. "online_remark" => $param['online_remark'],
  2342. "exam_status" => isset($all_nakes[$value]) ? ($all_nakes[$value] > 0 ? 2 : 1) : 1,
  2343. "is_online" => 0,
  2344. "status" => 0,
  2345. "is_del" => 0,
  2346. "creater" => $creater,
  2347. "createrid" => $createrid,
  2348. "addtime" => date("Y-m-d H:i:s"),
  2349. "updatetime" => date("Y-m-d H:i:s")
  2350. ];
  2351. //good表
  2352. if (!isset($all_good[$value])) {
  2353. $good_insert_data[] = [
  2354. 'spuCode' => $good_zixun_list[$value]['spuCode'],
  2355. 'good_code' => $good_zixun_list[$value]['good_code'],
  2356. 'good_name' => $good_zixun_list[$value]['good_name'],
  2357. 'cat_id' => $good_zixun_list[$value]['cat_id'],
  2358. 'brand_id' => $good_zixun_list[$value]['brand_id'],
  2359. 'good_unit' => $good_zixun_list[$value]['good_unit'],
  2360. 'good_type' => $good_zixun_list[$value]['good_type'],
  2361. 'companyNo' => $good_zixun_list[$value]['companyNo'],
  2362. 'moq' => $good_zixun_list[$value]['moq'],
  2363. 'customized' => $good_zixun_list[$value]['customized'],
  2364. 'tax' => $good_zixun_list[$value]['tax'],
  2365. 'supplierNo' => $good_zixun_list[$value]['supplierNo'],
  2366. 'is_auth' => $good_zixun_list[$value]['is_auth'],
  2367. 'is_stock' => '',
  2368. 'auth_img' => $good_zixun_list[$value]['auth_img'],
  2369. 'after_sales' => '',
  2370. 'craft_desc' => $good_zixun_list[$value]['craft_desc'],
  2371. 'good_remark' => $good_zixun_list[$value]['good_remark'],
  2372. 'good_size' => '',
  2373. 'weight' => $good_zixun_list[$value]['weight'],
  2374. 'packing_way' => '',
  2375. 'packing_size' => '',
  2376. 'packing_spec' => '',
  2377. 'packing_list' => '',
  2378. 'packing_weight' => '',
  2379. 'good_bar' => '',
  2380. 'supply_area' => $good_zixun_list[$value]['supply_area'],
  2381. 'delivery_place' => '',
  2382. 'origin_place' => '',
  2383. 'delivery_day' => 0,
  2384. 'lead_time' => '',
  2385. 'sample_day' => '',
  2386. 'sample_fee' => '',
  2387. 'good_img' => $good_zixun_list[$value]['good_img'],
  2388. 'good_thumb_img' => $good_zixun_list[$value]['good_thumb_img'],
  2389. 'good_info_img' => $good_zixun_list[$value]['good_info_img'],
  2390. 'cert_fee' => '',
  2391. 'packing_fee' => '',
  2392. 'cost_fee' => '',
  2393. 'mark_fee' => '',
  2394. 'demo_fee' => '',
  2395. 'open_fee' => '',
  2396. 'noble_metal' => $good_zixun_list[$value]['noble_metal'],
  2397. 'noble_weight' => $good_zixun_list[$value]['good_weight'],
  2398. 'is_gold_price' => $good_zixun_list[$value]['is_gold_price'],
  2399. 'cgd_gold_price' => '',
  2400. 'market_price' => '',
  2401. 'nake_price' => '',
  2402. 'is_step' => '',
  2403. 'is_online' => '',
  2404. 'status' => 1,//待完善成本
  2405. 'createrid' => $createrid,
  2406. 'creater' => $creater,
  2407. 'is_del' => 0,
  2408. 'field_change' => '',
  2409. 'addtime' => date('Y-m-d H:i:s'),
  2410. 'updatetime' => date('Y-m-d H:i:s'),
  2411. 'is_exclusive' => '',
  2412. 'is_diff' => $good_zixun_list[$value]['is_diff'],
  2413. 'config' => $good_zixun_list[$value]['config'],
  2414. 'other_config' => $good_zixun_list[$value]['other_config'],
  2415. ];
  2416. }
  2417. //good_basic表
  2418. if (!isset($all_good_basic[$value])) {
  2419. $good_basic_insert_data[] = [
  2420. 'spuCode' => $good_zixun_list[$value]['spuCode'],
  2421. 'good_code' => $good_zixun_list[$value]['good_code'],
  2422. 'good_name' => $good_zixun_list[$value]['good_name'],
  2423. 'cat_id' => $good_zixun_list[$value]['cat_id'],
  2424. 'brand_id' => $good_zixun_list[$value]['brand_id'],
  2425. 'companyNo' => $good_zixun_list[$value]['companyNo'],
  2426. 'good_unit' => $good_zixun_list[$value]['good_unit'],
  2427. 'good_type' => $good_zixun_list[$value]['good_type'],
  2428. 'moq' => $good_zixun_list[$value]['moq'],
  2429. 'customized' => $good_zixun_list[$value]['customized'],
  2430. 'tax' => $good_zixun_list[$value]['tax'],
  2431. 'supplierNo' => $good_zixun_list[$value]['supplierNo'],
  2432. 'is_auth' => $good_zixun_list[$value]['is_auth'],
  2433. 'auth_img' => $good_zixun_list[$value]['auth_img'],
  2434. 'after_sales' => '',
  2435. 'craft_desc' => $good_zixun_list[$value]['craft_desc'],
  2436. 'good_remark' => $good_zixun_list[$value]['good_remark'],
  2437. 'weight' => $good_zixun_list[$value]['weight'],
  2438. 'packing_way' => '',
  2439. 'packing_size' => '',
  2440. 'packing_spec' => '',
  2441. 'packing_list' => '',
  2442. 'packing_weight' => '',
  2443. 'good_bar' => '',
  2444. 'supply_area' => $good_zixun_list[$value]['supply_area'],
  2445. 'delivery_place' => '',
  2446. 'origin_place' => '',
  2447. 'delivery_day' => '',
  2448. 'lead_time' => '',
  2449. 'sample_day' => '',
  2450. 'sample_fee' => '',
  2451. 'good_img' => '',//$good_zixun_list[$value]['good_img'],
  2452. 'good_thumb_img' => $good_zixun_list[$value]['good_thumb_img'],
  2453. 'good_info_img' => $good_zixun_list[$value]['good_img'],//商品主图对应到商品详情
  2454. 'cert_fee' => '',
  2455. 'packing_fee' => '',
  2456. 'cost_fee' => '',
  2457. 'mark_fee' => '',
  2458. 'demo_fee' => '',
  2459. 'open_fee' => '',
  2460. 'noble_metal' => $good_zixun_list[$value]['noble_metal'],
  2461. 'noble_weight' => $good_zixun_list[$value]['good_weight'],
  2462. 'is_gold_price' => $good_zixun_list[$value]['is_gold_price'],
  2463. 'cgd_gold_price' => '',
  2464. 'market_price' => '',
  2465. 'nake_price' => '',
  2466. 'is_step' => '',
  2467. 'is_online' => '',
  2468. 'status' => 8,//咨询商品待编辑
  2469. 'createrid' => $createrid,
  2470. 'creater' => $creater,
  2471. 'field_change' => '',
  2472. 'is_del' => 0,
  2473. 'addtime' => date('Y-m-d H:i:s'),
  2474. 'updatetime' => date('Y-m-d H:i:s'),
  2475. 'is_diff' => $good_zixun_list[$value]['is_diff'],
  2476. 'config' => $good_zixun_list[$value]['config'],
  2477. 'other_config' => $good_zixun_list[$value]['other_config'],
  2478. ];
  2479. }
  2480. //good_spec
  2481. if (!empty($good_zixun_list[$value]['specinfo'])) {
  2482. $spec_list = json_decode($good_zixun_list[$value]['specinfo'], true);
  2483. foreach ($spec_list as $spec) {
  2484. $temp = Db::name('good_spec')
  2485. ->field('id')
  2486. ->where(['spuCode' => $value, 'spec_id' => $spec['specid'], 'spec_value_id' => $spec['spec_value_id'], 'is_del' => 0])
  2487. ->find();
  2488. if (!empty($temp)) {
  2489. $good_spec_insert_data[] = [
  2490. 'spuCode' => $value,
  2491. 'spec_id' => $spec['specid'],
  2492. 'spec_value_id' => $spec['spec_value_id'],
  2493. 'is_del' => 0,
  2494. 'addtime' => date('Y-m-d H:i:s'),
  2495. 'updatetime' => date('Y-m-d H:i:s'),
  2496. ];
  2497. }
  2498. }
  2499. }
  2500. $i++;
  2501. }
  2502. if (!empty($isonline)) {
  2503. return app_show(1009, "存在已上线产品", $isonline);
  2504. }
  2505. Db::startTrans();
  2506. try {
  2507. $create = Db::name("good_platform")->insertAll($data);
  2508. Db::name("good_zixun")
  2509. ->where(["is_del" => 0, 'status' => 1])
  2510. ->whereIn('spuCode', $param['codes'])
  2511. ->update(['status' => 2, 'updatetime' => date('Y-m-d H:i:s')]);
  2512. if (!empty($good_insert_data)) Db::name('good')->insertAll($good_insert_data);
  2513. if (!empty($good_basic_insert_data)) Db::name('good_basic')->insertAll($good_basic_insert_data);
  2514. if (!empty($good_spec_insert_data)) Db::name('good_spec')->insertAll($good_spec_insert_data);
  2515. if ($create) {
  2516. foreach ($good_basic_insert_data as $value) {
  2517. ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
  2518. "order_code" =>$value['spuCode'],//
  2519. "status" => 8,//待产品审核
  2520. "action_remark" => '',//备注
  2521. "action_type" => "create"//新建create,编辑edit,更改状态status
  2522. ], "SPCB", $value['status'], $value);
  2523. ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
  2524. "order_type" => 'SPCB',
  2525. "order_code" =>$value['spuCode'],//
  2526. "order_id" => isset($value['id']) ? $value['id'] : 0,
  2527. "order_status" => 8,//待产品审核
  2528. "before_status" => 0,//待产品审核
  2529. 'holder_id'=>$value['createrid'],
  2530. ]);
  2531. }
  2532. foreach ($data as $value) {
  2533. ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
  2534. "order_code" =>$value['skuCode'],//
  2535. "status" => 0,//待产品审核
  2536. "action_remark" => '',//备注
  2537. "action_type" => "create"//新建create,编辑edit,更改状态status
  2538. ], "SPSX", $value['exam_status'], $value);
  2539. ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
  2540. "order_type" => 'SPSX',
  2541. "order_code" =>$value['skuCode'],//
  2542. "order_id" => isset($value['id']) ? $value['id'] : 0,
  2543. "order_status" =>$value['exam_status'],//待产品审核
  2544. "before_status" => 0,
  2545. 'holder_id' => $value['createrid'],
  2546. ]);
  2547. }
  2548. Db::commit();
  2549. return app_show(0, "提交成功");
  2550. } else {
  2551. Db::rollback();
  2552. return error_show(1004, "提交失败");
  2553. }
  2554. } catch (Exception $exception) {
  2555. Db::rollback();
  2556. return error_show(1005, $exception->getMessage());
  2557. }
  2558. }
  2559. //商品上线审核流程时,驳回重新审核
  2560. public function rejectGoodToAgainExamine()
  2561. {
  2562. $param = $this->request->only(['token', 'skuCode', 'exam_remark' => ''], 'post', 'trim');
  2563. $val = Validate::rule(['token' => 'require', 'skuCode' => 'require']);
  2564. if (!$val->check($param)) return error_show(1005, $val->getError());
  2565. $user = GetUserInfo($param['token']);
  2566. $createrid = isset($user['data']['id']) ? $user['data']['id'] : 0;
  2567. $creater = isset($user['data']['nickname']) ? $user['data']['nickname'] : '';
  2568. Db::startTrans();
  2569. try {
  2570. $rs = Db::name("good_platform")
  2571. ->field('id,spuCode,skuCode,exam_status,createrid')
  2572. ->where(['skuCode' => $param['skuCode'], 'is_del' => 0])
  2573. ->where('exam_status', '<>', 6)//exam_status==6上线成功
  2574. ->find();
  2575. if (empty($rs)) throw new \Exception('该记录不存在');
  2576. $old_exam_staus = $rs['exam_status'];
  2577. $good_nake = Db::name("good_nake")
  2578. ->field('id')
  2579. ->where(["spuCode" => $rs['spuCode'], "is_del" => 0])
  2580. ->find();
  2581. $exam_status = empty($good_nake) ? 1 : 2;
  2582. if ($exam_status == $rs['exam_status']) $exam_status = 7;//第一级审核失败时,状态改为'审核失败'
  2583. Db::name("good_platform")
  2584. ->where('id', $rs['id'])
  2585. ->save([
  2586. 'exam_status' => $exam_status,
  2587. 'updatetime' => date('Y-m-d H:i:s'),
  2588. ]);
  2589. Db::name("good_exam")->insert([
  2590. 'code' => $rs['skuCode'],
  2591. 'exam_status' => $old_exam_staus,
  2592. 'type' => 2,
  2593. 'exam_id' => $createrid,
  2594. 'exam_name' => $creater,
  2595. 'exam_remark' => $param['exam_remark'],
  2596. 'addtime' => date('Y-m-d H:i:s')
  2597. ]);
  2598. ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
  2599. "order_code" => $param['skuCode'],//编号
  2600. "status" => $rs['exam_status'],
  2601. "action_remark" => '',//备注
  2602. "action_type" => "status"//新建create,编辑edit,更改状态status
  2603. ], "SPSX", $exam_status, $param);
  2604. ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
  2605. "order_type" => 'SPSX',
  2606. "order_code" => $param['skuCode'],//咨询单详情编号
  2607. "order_id" => $rs['id'],
  2608. "order_status" => $exam_status,
  2609. "before_status" => $rs['exam_status'],
  2610. 'holder_id' => $rs['createrid'],
  2611. ]);
  2612. Db::commit();
  2613. return app_show(0, "驳回重新审核成功");
  2614. } catch (\Exception $e) {
  2615. Db::rollback();
  2616. return error_show(1004, '驳回重新审核失败,' . $e->getMessage());
  2617. }
  2618. }
  2619. //同一个spuCode下所有的商品都下线
  2620. public function offlineGoodBySpuCode()
  2621. {
  2622. $param = $this->request->only(['token', 'spuCode', 'offline_reason', 'offline_remark' => ''], 'post', 'trim');
  2623. $val = Validate::rule(['token' => 'require', 'spuCode' => 'require', 'offline_reason|下线原因' => 'require']);
  2624. if (!$val->check($param)) return error_show(1005, $val->getError());
  2625. $user = GetUserInfo($param['token']);
  2626. $createrid = isset($user['data']['id']) ? $user['data']['id'] : 0;
  2627. $creater = isset($user['data']['nickname']) ? $user['data']['nickname'] : '';
  2628. Db::startTrans();
  2629. try {
  2630. $good_name = Db::name("good_basic")
  2631. ->where(['is_del' => 0, 'spuCode' => $param['spuCode']])
  2632. ->value('good_name', '');
  2633. $skuCodeS = Db::name("good_platform")
  2634. ->where(['spuCode' => $param['spuCode'], 'is_del' => 0, 'exam_status' => 6])//exam_status 7审核失败,8已下线
  2635. ->column('exam_status,skuCode', 'skuCode');
  2636. if ($skuCodeS) {
  2637. // if (empty($skuCodeS)) throw new \Exception('该商品未在任何平台申请上线');
  2638. //商品平台
  2639. Db::name("good_platform")
  2640. ->where(['spuCode' => $param['spuCode'], 'is_del' => 0, 'exam_status' => 6])
  2641. ->save([
  2642. 'exam_status' => 8,
  2643. 'updatetime' => date('Y-m-d H:i:s'),
  2644. ]);
  2645. //商品下线记录
  2646. $good_offline_log_id = Db::name("good_offline_log")->insertGetId([
  2647. 'spuCode' => $param['spuCode'],
  2648. 'skuCodes' => implode(',', array_keys($skuCodeS)),
  2649. 'good_name' => $good_name,
  2650. 'offline_reason' => $param['offline_reason'],
  2651. 'offline_remark' => $param['offline_remark'],
  2652. 'createrid' => $createrid,
  2653. 'creater' => $creater,
  2654. 'addtime' => date('Y-m-d H:i:s'),
  2655. ]);
  2656. //根据权限查询应该接收商品下线通知的人员
  2657. $all_uid_name = Db::name('role_action')
  2658. ->whereFindInSet('action_conllect', '877')//数据写死的,要注意各个环境数据是否一致
  2659. ->field('role_id')
  2660. ->buildSql();
  2661. $all_user = Db::name('user_role')
  2662. ->alias('ur')
  2663. ->where('ur.roleid IN ' . $all_uid_name)
  2664. ->leftJoin('depart_user du', 'du.uid = ur.uid AND du.is_del=0')
  2665. ->column('ur.uid,du.nickName');
  2666. $insert_good_exam_data = $insert_order_msg_data = [];
  2667. foreach ($skuCodeS as $skuCode => $value) {
  2668. $insert_good_exam_data[] = [
  2669. 'code' => $skuCode,
  2670. 'exam_status' => 8,
  2671. 'type' => 2,
  2672. 'exam_id' => $createrid,
  2673. 'exam_name' => $creater,
  2674. 'exam_remark' => '',
  2675. 'addtime' => date('Y-m-d H:i:s')
  2676. ];
  2677. ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
  2678. "order_code" => $skuCode,//编号
  2679. "status" => 6,
  2680. "action_remark" => '',//备注
  2681. "action_type" => "status"//新建create,编辑edit,更改状态status
  2682. ], "GOL", 8, $param);
  2683. ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
  2684. "order_type" => 'GOL',
  2685. "order_code" => $skuCode,
  2686. "order_id" => $good_offline_log_id,
  2687. "order_status" => 8,
  2688. "before_status" => $value['exam_status']
  2689. ]);
  2690. foreach ($all_user as $itemitem) {
  2691. $insert_order_msg_data[] = [
  2692. 'content' => '商品下线:' . $skuCode . '由' . $creater . '操作下线',
  2693. 'orderCode' => $skuCode,
  2694. 'order_type' => 'GOL',
  2695. 'order_status' => 8,
  2696. 'order_id' => $good_offline_log_id,
  2697. 'uid' => $itemitem['uid'],
  2698. 'uname' => empty($itemitem['nickName']) ? '' : $itemitem['nickName'],
  2699. 'apply_id' => $createrid,
  2700. 'apply_name' => $creater,
  2701. 'is_read' => 0,
  2702. 'addtime' => date('Y-m-d H:i:s'),
  2703. 'updatetime' => date('Y-m-d H:i:s'),
  2704. ];
  2705. }
  2706. }
  2707. //变动记录
  2708. Db::name("good_exam")->insertAll($insert_good_exam_data);
  2709. //消息表
  2710. Db::name('order_msg')->insertAll($insert_order_msg_data);
  2711. }
  2712. //处理有赞平台
  2713. $rs = Db::name('platform_youzan')
  2714. ->field('id,spuCode,skuCode,exam_status,platform_id')
  2715. ->where(['spuCode' => $param['spuCode'], 'is_del' => PlatformYouzan::$del_normal])
  2716. ->whereNotIn('exam_status', [PlatformYouzan::$exam_status_7, PlatformYouzan::$exam_status_8])
  2717. ->select()
  2718. ->toArray();
  2719. if ($rs) {
  2720. $insert_good_offline_log_youzan_data = [];
  2721. foreach ($rs as $value) {
  2722. $curl_data = [
  2723. 'item_no' => $value['skuCode'],//商品自定义编码 skuCode
  2724. 'uid' => $createrid,
  2725. 'nickname' => $creater,
  2726. ];
  2727. //已上线的要调用有赞接口下线
  2728. //调有赞项目的接口,从有赞平台下线该商品
  2729. if($value['exam_status'] == PlatformYouzan::$exam_status_6){
  2730. $host = config('app.yz_domain');
  2731. $response = curl_request($host . 'api/yz_goodup_offline', $curl_data);
  2732. $response = json_decode($response, true);
  2733. if ($response['code'] != 0) throw new Exception($response['message']);
  2734. }
  2735. $insert_good_offline_log_youzan_data[] = [
  2736. 'spuCode' => $value['spuCode'],
  2737. 'skuCodes' => $value['skuCode'],
  2738. 'good_name' => $good_name,
  2739. 'offline_reason' => $param['offline_reason'],
  2740. 'offline_remark' => $param['offline_remark'],
  2741. 'createrid' => $createrid,
  2742. 'creater' => $creater,
  2743. 'addtime' => date('Y-m-d H:i:s')
  2744. ];
  2745. }
  2746. Db::name('platform_youzan')
  2747. ->where(['spuCode' => $param['spuCode'], 'is_del' => PlatformYouzan::$del_normal])
  2748. ->whereNotIn('exam_status', [PlatformYouzan::$exam_status_7, PlatformYouzan::$exam_status_8])
  2749. ->update([
  2750. 'exam_status' => PlatformYouzan::$exam_status_8,
  2751. 'offline_reason_id' => $param['offline_reason'],
  2752. 'offline_remark' => $param['offline_remark'],
  2753. 'updaterid' => $createrid,
  2754. 'updater' => $creater,
  2755. 'updatetime' => date('Y-m-d H:i:s')
  2756. ]);
  2757. //下线记录表增加记录
  2758. if ($insert_good_offline_log_youzan_data) Db::name('good_offline_log_youzan')->insertAll($insert_good_offline_log_youzan_data);
  2759. }
  2760. Db::commit();
  2761. return app_show(0, "下线成功");
  2762. } catch (\Exception $e) {
  2763. Db::rollback();
  2764. return error_show(1004, '操作失败,' . $e->getMessage());
  2765. }
  2766. }
  2767. //判断是否允许修改成本信息和基础信息
  2768. public function checkIsUpdate()
  2769. {
  2770. $spuCode = $this->request->post('spuCode', '', 'trim');
  2771. if ($spuCode == '') return error_show(1004, '成本商品编号不能为空');
  2772. $is_allow_update = 1;
  2773. //检查是否有上线记录
  2774. $rs = Db::name('good_platform')
  2775. ->field('id')
  2776. ->where(['spuCode' => $spuCode, 'is_del' => 0])
  2777. ->whereNotIn('exam_status', [0, 8])
  2778. ->find();
  2779. if (!empty($rs)) $is_allow_update = 0;
  2780. else {
  2781. $rs = PlatformYouzan::field('id')
  2782. ->where(['spuCode' => $spuCode, 'is_del' => PlatformYouzan::$del_normal])
  2783. ->whereNotIn('exam_status', [PlatformYouzan::$exam_status_8,PlatformYouzan::$exam_status_2])
  2784. ->findOrEmpty()
  2785. ->isEmpty();
  2786. if (!$rs) $is_allow_update = 0;
  2787. }
  2788. return app_show(0, '请求成功', ['is_allow_update' => $is_allow_update]);
  2789. }
  2790. //获取某个商品编号下的所有审核备注列表
  2791. public function getGoodExamList()
  2792. {
  2793. $param = $this->request->filter('trim')->only(['token', 'skuCode', 'page' => 1, 'size' => 15], 'post');
  2794. $val = Validate::rule(['token' => 'require', 'skuCode' => 'require']);
  2795. if (!$val->check($param)) return error_show(1005, $val->getError());
  2796. $count = Db::name('good_exam')
  2797. ->where('code', $param['skuCode'])
  2798. ->count('id');
  2799. $list = Db::name('good_exam')
  2800. ->where('code', $param['skuCode'])
  2801. ->order('id')
  2802. ->page($param['page'], $param['size'])
  2803. ->select()
  2804. ->toArray();
  2805. return app_show(0, '请求成功', ['list' => $list, 'count' => $count]);
  2806. }
  2807. }