Goodup.php 145 KB

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