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