Goodup.php 125 KB

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