Goodup.php 124 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453
  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
  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']
  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']
  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
  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. if($is_gold_price==1 && $datas['cat_id']==6){
  846. //$gold =Db::name("gold_price1")->where(["type"=>$noble_metal,"status"=>1,"is_del"=>0])
  847. // ->order("addtime desc")->find();
  848. //$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'];
  849. //成本合计=贵金属重量*供应商采购金价 + 工艺费*贵金属重量+加标费+包装费+证书费+成本裸价+运费+其他费用
  850. //成本总计启用实时金价时,采用供应商实时金价
  851. $lemp['nake_total'] = $noble_weight * $cgd_gold_price+ $value['cost_fee'] * $noble_weight +
  852. $value['mark_fee'] + $value['package_fee'] + $value['cert_fee'] + $value['nake_fee'] + $value['delivery_fee'] + $value['other_fee'];
  853. }else{
  854. $lemp['nake_total'] =$value['nake_fee']+$value['delivery_fee']+$value['cert_fee']+$value['mark_fee']+$value['package_fee']+$value['other_fee'];
  855. }
  856. $lemp['is_del'] = isset($value['is_del'])?$value['is_del']:0;
  857. $lemp['creater_id'] = isset($user["data"]['id']) ? $user["data"]['id'] : "";
  858. $lemp['creater'] =isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  859. isset($value["id"])&&$value["id"]!=''?"": $lemp['addtime'] = date("Y-m-d H:i:s");
  860. $lemp['updatetime'] =date("Y-m-d H:i:s");
  861. $count = Db::name("good_nake")->save($lemp);
  862. if($count==false){
  863. Db::rollback();
  864. return app_show(1004,"商品规成本修改失败");
  865. }
  866. }
  867. }
  868. Db::commit();
  869. return app_show(0,"更新成功");
  870. }else{
  871. Db::rollback();
  872. return error_show(1005,"更新失败");
  873. }
  874. }catch (\Exception $e){
  875. Db::rollback();
  876. return error_show(1005,$e->getMessage());
  877. }
  878. }
  879. public function exam(){
  880. $supcode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):"";
  881. if($supcode==""){
  882. return error_show(1004,"参数spuCode不能为空");
  883. }
  884. $data = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->find();
  885. if($data==false){
  886. return error_show(1004,"未找到商品数据");
  887. }
  888. if($data['status']==1){
  889. return error_show(1004,"商品已审核通过");
  890. }
  891. $status = isset($this->post['status'])&&$this->post['status']!=="" ? intval($this->post['status']):"";
  892. // if($status===""){
  893. // return error_show(1004,"参数status不能为空");
  894. // }
  895. $remark = isset($this->post['remark'])&&$this->post['remark']!=="" ? trim($this->post['remark']):"";
  896. // if($remark===""){
  897. // return error_show(1004,"参数remark不能为空");
  898. // }
  899. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  900. if($token==''){
  901. return error_show(105,"参数token不能为空");
  902. }
  903. $user =GetUserInfo($token);
  904. if(empty($user)||$user['code']!=0){
  905. return error_show(1002,"用户数据不存在");
  906. }
  907. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  908. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  909. Db::startTrans();
  910. try {
  911. if($data['status']==3 && $status==1){
  912. $online = Db::name("good_platform")->where(["spuCode"=>$supcode,"is_del"=>0])->find();
  913. if($online) {
  914. $onl= Db::name("good_platform")->where(["spuCode" => $supcode, "is_del" => 0])->save(["exam_status" => 2, "updatetime" => date("Y-m-d H:i:s")]);
  915. if ($onl != false) {
  916. Db::rollback();
  917. return error_show(1004, "审核失败");
  918. }
  919. ActionLog::logAdd($this->post['token'], [
  920. "order_code" =>$online['skuCode'],//咨询单详情编号
  921. "status" => $online['exam_status'],//这里的status是之前的值
  922. "action_remark" => '',//备注
  923. "action_type" => "edit"//新建create,编辑edit,更改状态status
  924. ], "SPSX", 2, ["exam_status" => 2, "updatetime" => date("Y-m-d H:i:s")]);
  925. ProcessOrder::AddProcess($this->post['token'], [
  926. "order_type" => 'SPSX',
  927. "order_code" =>$online['skuCode'],//咨询单详情编号
  928. "order_id" => $online['id'],
  929. "order_status" => 2
  930. ]);
  931. }
  932. }
  933. // if ($status == 1) {
  934. // //把同一个spuCode,且状态为1待完善成本,的记录更改状态为2待产品审核
  935. // Db::name('good')
  936. // ->where(['is_del' => 0, 'status' => 1])
  937. // ->whereIn('spuCode', $supcode)
  938. // ->update(['status' => 2, 'updatetime' => date('Y-m-d H:i:s')]);
  939. // }
  940. $data['status']=$status;
  941. $data['updatetime']=date("Y-m-d H:i:s");
  942. $up= Db::name("good_basic")->save($data);
  943. if($up){
  944. //修改状态,添加待办
  945. ActionLog::logAdd($this->post['token'], [
  946. "order_code" =>$supcode,//咨询单详情编号
  947. "status" => $status,//这里的status是之前的值
  948. "action_remark" => '',//备注
  949. "action_type" => "edit"//新建create,编辑edit,更改状态status
  950. ], "SPCB",$data['status'] ,$data);
  951. ProcessOrder::AddProcess($this->post['token'], [
  952. "order_type" => 'SPCB',
  953. "order_code" => $supcode,//咨询单详情编号
  954. "order_id" => $data['id'],
  955. "order_status" =>$data['status']
  956. ]);
  957. $data=[
  958. "code"=>$supcode,
  959. "exam_status"=>$status,
  960. "type"=>1,
  961. "exam_id"=>$createrid,
  962. "exam_name"=>$creater,
  963. "exam_remark"=>$remark,
  964. "addtime"=>date("Y-m-d H:i:s")
  965. ];
  966. $inr=Db::name("good_exam")->insert($data);
  967. if($inr){
  968. Db::commit();
  969. return app_show(0,"审核成功");
  970. }else{
  971. Db::rollback();
  972. return error_show(1004,"审核失败");
  973. }
  974. }else{
  975. Db::rollback();
  976. return error_show(1004,"审核失败");
  977. }
  978. }catch (\Exception $e){
  979. Db::rollback();
  980. return error_show(1004,$e->getMessage());
  981. }
  982. }
  983. public function info(){
  984. $supcode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):"";
  985. if($supcode==""){
  986. return error_show(1004,"参数spuCode不能为空");
  987. }
  988. $data = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->find();
  989. if($data==false){
  990. return error_show(1004,"未找到商品数据");
  991. }
  992. $unit =Db::name("unit")->where(["id"=>$data['good_unit']])->find();
  993. $data['unit'] = isset($unit['unit'])?$unit['unit']:'';
  994. $data['cat_info'] = made($data['cat_id'],[]);
  995. $spec = Db::name("good_spec")->where(["spuCode"=>$supcode,"is_del"=>0])->select()->toArray();
  996. $supplier = Db::name("supplier")->where(["code"=>$data['supplierNo']])->find();
  997. $data['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  998. $supplier = Db::name("supplier")->where(["code"=>$data['supplierNo']])->find();
  999. $data['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  1000. $company = Db::name("business")->where(["companyNo"=>$data['companyNo']])->find();
  1001. $data['company'] = isset($company['company'])?$company['company']:"";
  1002. $data['field_change'] = $data['field_change']!=''?json_decode($data['field_change']):"";
  1003. if($data['brand_id']!=0){
  1004. $brand=Db::name("brand")->where(["id"=>$data['brand_id']])->find();
  1005. $data["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1006. }else{
  1007. $data["brand_name"]="";
  1008. $data["brand_id"]="";
  1009. }
  1010. $excluse = makeExcluse($data['is_exclusive']);
  1011. $data['exclusive']=$excluse;
  1012. $data['noble_name']=isset($data['noble_metal'])&&$data['noble_metal']!=0?$this->noble[$data['noble_metal']] :"";
  1013. $data["good_info_img"]=$data['good_info_img']!=""? $data['good_info_img']:'';
  1014. $data["good_img"]=$data['good_img']!=""? $data['good_img']:[];
  1015. $gold=[];
  1016. if ($data['is_gold_price'] == 1) {
  1017. $gold = Db::name("gold_price1")->where(["type" => $data['noble_metal'], "status" => 1, "is_del" => 0])->order("addtime desc")->find();
  1018. }
  1019. $data['gold_price'] =isset($gold["price"])?$gold["price"]:0;
  1020. $speclist=[];
  1021. if(!empty($spec)){
  1022. foreach ($spec as $value){
  1023. $temp=[];
  1024. $temp['id']=$value['id'];
  1025. $temp['spuCode']=$value['spuCode'];
  1026. $temp['spec_id']=$value['spec_id'];
  1027. $temp['spec_value_id']=$value['spec_value_id'];
  1028. $temp['is_del']=$value['is_del'];
  1029. $sp = Db::name("specs")->where(["id"=>$value['spec_id']])->find();
  1030. $temp['spec_name']=isset($sp["spec_name"]) ? $sp["spec_name"]:"";
  1031. $spv = Db::name("spec_value")->where(["id"=>$value['spec_value_id']])->find();
  1032. $temp['spec_value']=isset($spv["spec_value"]) ? $spv["spec_value"]:"";
  1033. $speclist[]=$temp;
  1034. }
  1035. }
  1036. $data["speclist"]=empty($speclist)?[]:$speclist;
  1037. // $nake=[];
  1038. $nakelist = Db::name("good_nake")->where(['spuCode'=>$supcode,"is_del"=>0])->select()->toArray();
  1039. // $catinfo = Db::name("cat")->where(["id"=>$data['cat_id']])->find();
  1040. // $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  1041. $nakearry=[];
  1042. if(!empty($nakelist)){
  1043. foreach ($nakelist as $value) {
  1044. $nakearry[] = $value;
  1045. }
  1046. }
  1047. $data["nakelist"]=$nakearry;
  1048. return app_show(0,"获取成功",$data);
  1049. }
  1050. //删除商品成本
  1051. public function delall()
  1052. {
  1053. // $supcode = isset($this->post['codes'])&&!empty($this->post['codes'])? $this->post['codes']:"";
  1054. $supcode = $this->request->post('codes', '', 'trim');
  1055. if ($supcode == "") {
  1056. return error_show(1004, "参数codes不能为空");
  1057. }
  1058. Db::startTrans();
  1059. try {
  1060. $good_basic = Db::name("good_basic")
  1061. ->field('id,spuCode,status')
  1062. ->where(["spuCode" => $supcode, "is_del" => 0])
  1063. ->find();
  1064. if (empty($good_basic)) throw new Exception('该记录不存在或已删除');
  1065. $good = Db::name('good')
  1066. ->field('id,status')
  1067. ->where(['spuCode' => $supcode, 'is_del' => 0])
  1068. ->whereIn('status', [1, 8])
  1069. ->find();
  1070. if (empty($good)) throw new Exception('该上线商品记录不存在或不允许删除,请检查商品是否下线');
  1071. Db::name("good_basic")
  1072. ->where(['id' => $good_basic['id'], 'is_del' => 0])
  1073. ->update(['is_del' => 1, 'updatetime' => date('Y-m-d H:i:s')]);
  1074. Db::name("good")
  1075. ->where(['id' => $good['id'], 'is_del' => 0])
  1076. ->update(['is_del' => 1, 'updatetime' => date('Y-m-d H:i:s')]);
  1077. ProcessOrder::workdel(["order_type" => "CGD", "order_code" => $supcode]);
  1078. Db::commit();
  1079. app_show(0, "删除成功");
  1080. } catch (Exception $exception) {
  1081. Db::rollback();
  1082. return error_show(1005, "删除失败");
  1083. }
  1084. // $data = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->select()->toArray();
  1085. // if(empty($data)){
  1086. // return error_show(1004,"未找到商品数据");
  1087. // }
  1088. // $up= Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->save(["is_del"=>1]);
  1089. // if($up){
  1090. // ProcessOrder::workdel(["order_type"=>"CGD","order_code"=>$supcode]);
  1091. // return app_show(0,"更新成功");
  1092. // }else{
  1093. // return error_show(1005,"更新失败");
  1094. // }
  1095. }
  1096. //添加上线商品
  1097. public function online(){
  1098. $platform =isset($this->post['platform'])&&!empty($this->post['platform'])? $this->post['platform']:"";
  1099. if($platform==""){
  1100. return error_show(1004,"参数codes不能为空");
  1101. }
  1102. $spuCode =isset($this->post['codes'])&&!empty($this->post['codes'])? $this->post['codes']:"";
  1103. if($spuCode===''){
  1104. return error_show(1004,"参数codes不能为空");
  1105. }
  1106. $datas = Db::name("good_basic")->where(["spuCode"=>$spuCode,"is_del"=>0])->select()->toArray();
  1107. if(empty($datas)){
  1108. return error_show(1004,"未找到商品数据");
  1109. }
  1110. $online_reason = isset($this->post['online_reason'])&&$this->post['online_reason']!==""? trim($this->post['online_reason']):"";
  1111. if($online_reason===""){
  1112. return error_show(1004,"参数online_reason不能为空");
  1113. }
  1114. $online_remark= isset($this->post['online_remark'])&&$this->post['online_remark']!==""? trim($this->post['online_remark']):"";
  1115. if($online_remark===""){
  1116. return error_show(1004,"参数online_remark不能为空");
  1117. }
  1118. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1119. if($token==''){
  1120. return error_show(105,"参数token不能为空");
  1121. }
  1122. $user =GetUserInfo($token);
  1123. if(empty($user)||$user['code']!=0){
  1124. return error_show(1002,"用户数据不存在");
  1125. }
  1126. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1127. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1128. $data=[];
  1129. $isonline=[];
  1130. $i=0;
  1131. Db::startTrans();
  1132. try{
  1133. foreach ($datas as $value){
  1134. $count = Db::name("good_nake")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->count();
  1135. $ist =Db::name("good_platform")->where(["spuCode"=>$value['spuCode'],"platform_code"=>$platform,"is_del"=>0])->find();
  1136. if($ist){
  1137. $god=Db::name("good_basic")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->find();
  1138. if($god){
  1139. $tp=[];
  1140. $tp['spuCode']=$value['spuCode'];
  1141. $tp['good_name']=$god['good_name'];
  1142. $tp['good_img']=$god['good_thumb_img'];
  1143. $tp['exam_status']=$ist['exam_status'];
  1144. $spec = Db::name("good_spec")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->select()->toArray();
  1145. $speclist=[];
  1146. if(!empty($spec)){
  1147. foreach ($spec as $val){
  1148. $temp=[];
  1149. $temp['id']=$val['id'];
  1150. $temp['spuCode']=$val['spuCode'];
  1151. $temp['spec_id']=$val['spec_id'];
  1152. $temp['spec_value_id']=$val['spec_value_id'];
  1153. $temp['is_del']=$val['is_del'];
  1154. $sp = Db::name("specs")->where(["id"=>$val['spec_id']])->find();
  1155. $temp['spec_name']=isset($sp["spec_name"]) ? $sp["spec_name"]:"";
  1156. $spv = Db::name("spec_value")->where(["id"=>$val['spec_value_id']])->find();
  1157. $temp['spec_value']=isset($spv["spec_value"]) ? $spv["spec_value"]:"";
  1158. $speclist[]=$temp;
  1159. }
  1160. }
  1161. $tp["speclist"]=empty($speclist)?[]:$speclist;
  1162. $isonline[]=$tp;
  1163. }
  1164. }
  1165. if(!empty($isonline)){
  1166. return app_show(1009,"存在已上线产品",$isonline);
  1167. }
  1168. //改变编码规则,将原来的skuCode后两位换成序列号
  1169. //str_pad字符串填充
  1170. $skuCode = makeNo("SN");
  1171. $skuCode = substr($skuCode, 0, -2) . str_pad($i, 2, '0', STR_PAD_LEFT);
  1172. $tmp=[
  1173. "spuCode"=>$value['spuCode'],
  1174. "skuCode"=>$skuCode,
  1175. "platform_code"=>$platform,
  1176. "online_reason"=>$online_reason,
  1177. "online_remark"=>$online_remark,
  1178. "exam_status"=>$count>0 ?2:1,
  1179. "is_online"=>0,
  1180. "status"=>1,
  1181. "is_del"=>0,
  1182. "creater"=>$creater,
  1183. "createrid"=>$createrid,
  1184. "addtime"=>date("Y-m-d H:i:s"),
  1185. "updatetime"=>date("Y-m-d H:i:s")
  1186. ];
  1187. $i++;
  1188. //修改状态,添加待办
  1189. $create =Db::name("good_platform")->insert($tmp,true);
  1190. if($create>0){
  1191. ActionLog::logAdd($this->post['token'], [
  1192. "order_code" =>$skuCode,//咨询单详情编号
  1193. "status" => $tmp['exam_status'],//这里的status是之前的值
  1194. "action_remark" => '',//备注
  1195. "action_type" => "create"//新建create,编辑edit,更改状态status
  1196. ], "SPSX",$tmp['exam_status'],$tmp);
  1197. ProcessOrder::AddProcess($this->post['token'], [
  1198. "order_type" => 'SPSX',
  1199. "order_code" =>$skuCode,//咨询单详情编号
  1200. "order_id" => $create,
  1201. "order_status" =>$tmp['exam_status']
  1202. ]);
  1203. $iso = Db::name("good")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->find();
  1204. if($iso==false){
  1205. unset($value['id']);
  1206. $value['creater']=$creater;
  1207. $value['createrid']=$createrid;
  1208. $value['addtime']=date("Y-m-d H:i:s");
  1209. $value['updatetime']=date("Y-m-d H:i:s");
  1210. }else{
  1211. $value['id']=$iso['id'];
  1212. $value['creater']=$creater;
  1213. $value['createrid']=$createrid;
  1214. $value['updatetime']=date("Y-m-d H:i:s");
  1215. }
  1216. $up =Db::name("good")->save($value);
  1217. if(!$up){
  1218. Db::rollback();
  1219. return error_show(1004,"提交失败");
  1220. }
  1221. }else{
  1222. Db::rollback();
  1223. return error_show(1004,"提交失败");
  1224. }
  1225. }
  1226. // if($create){
  1227. // foreach ($datas as $value){
  1228. // $iso = Db::name("good")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->find();
  1229. // if($iso==false){
  1230. // unset($value['id']);
  1231. // $value['creater']=$creater;
  1232. // $value['createrid']=$createrid;
  1233. // $value['addtime']=date("Y-m-d H:i:s");
  1234. // $value['updatetime']=date("Y-m-d H:i:s");
  1235. // }else{
  1236. // $value['id']=$iso['id'];
  1237. // $value['creater']=$creater;
  1238. // $value['createrid']=$createrid;
  1239. // $value['updatetime']=date("Y-m-d H:i:s");
  1240. // }
  1241. // $up =Db::name("good")->save($value);
  1242. // if(!$up){
  1243. // Db::rollback();
  1244. // return error_show(1004,"提交失败");
  1245. // }
  1246. //
  1247. // //添加审核记录
  1248. // //修改状态,添加待办
  1249. // $skuCodes = array_column($data, 'skuCode', 'spuCode');
  1250. //
  1251. // ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
  1252. // "order_code" => $skuCodes[$value['spuCode']],//编号
  1253. // "status" => 2,//待产品审核
  1254. // "action_remark" => '',//备注
  1255. // "action_type" => "create"//新建create,编辑edit,更改状态status
  1256. // ], "SPSX", $value['status'], $value);
  1257. //
  1258. // ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
  1259. // "order_type" => 'SPSX',
  1260. // "order_code" => $skuCodes[$value['spuCode']],//咨询单详情编号
  1261. // "order_id" => isset($value['id']) ? $value['id'] : 0,
  1262. // "order_status" => 2,//待产品审核
  1263. // ]);
  1264. // }
  1265. // Db::commit();
  1266. // return app_show(0,"提交成功");
  1267. // }else{
  1268. // Db::rollback();
  1269. // return error_show(1004,"提交失败");
  1270. // }
  1271. Db::commit();
  1272. return app_show(0,"提交成功");
  1273. }catch (\Exception $e){
  1274. Db::rollback();
  1275. return error_show(1004,$e->getMessage()."|".$e->getLine());
  1276. }
  1277. }
  1278. //审核
  1279. public function online_exam(){
  1280. $skuCode = isset($this->post['skuCode'])&&$this->post['skuCode']!==""?trim($this->post['skuCode']):"";
  1281. if($skuCode===""){
  1282. return error_show(1004,"参数skuCode不能为空");
  1283. }
  1284. $platform = Db::name("good_platform")->where(["skuCode"=>$skuCode,"is_del"=>0])->find();
  1285. if($platform==false){
  1286. return error_show(1004,"未找到数据");
  1287. }
  1288. $exam_status=isset($this->post['exam_status'])&&$this->post['exam_status']!==""?intval($this->post['exam_status']):"";
  1289. // if($exam_status===""){
  1290. // return error_show(1004,"参数exam_status不能为空");
  1291. // }
  1292. if($exam_status==3){
  1293. $online_time= isset($this->post['online_time'])&&$this->post['online_time']!==""?$this->post['online_time']:"";
  1294. if($online_time===""){
  1295. return error_show(1004,"参数online_time不能为空");
  1296. }
  1297. $platform['online_time']=$online_time;
  1298. }
  1299. if($exam_status==6){
  1300. $good_code= isset($this->post['plat_code'])&&$this->post['plat_code']!==""?trim($this->post['plat_code']):"";
  1301. if($good_code===""){
  1302. return error_show(1004,"参数plat_code不能为空");
  1303. }
  1304. $is_exit = Db::name("good_platform")->where(["plat_code"=>$good_code,"is_del"=>0])->find();
  1305. if(($is_exit!=false && $is_exit['id'] !=$platform['id'])|| $is_exit==false){
  1306. $platform['plat_code']=$good_code;
  1307. }else{
  1308. return error_show(1004,"平台订单号 {$good_code} 已存在");
  1309. }
  1310. }
  1311. $exam_remark = isset($this->post['exam_remark'])&&$this->post['exam_remark']!==""?trim($this->post['exam_remark']):"";
  1312. $bifore=$platform['exam_status'];
  1313. $platform['exam_status']=$exam_status;
  1314. $platform['updatetime']=date("Y-m-d H:i:s");
  1315. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1316. if($token==''){
  1317. return error_show(105,"参数token不能为空");
  1318. }
  1319. $user =GetUserInfo($token);
  1320. if(empty($user)||$user['code']!=0){
  1321. return error_show(1002,"用户数据不存在");
  1322. }
  1323. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1324. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1325. Db::startTrans();
  1326. try {
  1327. $up = Db::name("good_platform")->save($platform);
  1328. if($up){
  1329. $data=[
  1330. "code"=>$platform['skuCode'],
  1331. "exam_status"=>$exam_status,
  1332. "type"=>2,
  1333. "exam_id"=>$createrid,
  1334. "exam_name"=>$creater,
  1335. "exam_remark"=>$exam_remark,
  1336. "addtime"=>date("Y-m-d H:i:s")
  1337. ];
  1338. $inr=Db::name("good_exam")->insert($data);
  1339. if($inr){
  1340. ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
  1341. "order_code" => $skuCode,//编号
  1342. "status" => $bifore,
  1343. "action_remark" => '',//备注
  1344. "action_type" => "status"//新建create,编辑edit,更改状态status
  1345. ], "SPSX", $exam_status, $platform);
  1346. ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
  1347. "order_type" => 'SPSX',
  1348. "order_code" => $skuCode,//咨询单详情编号
  1349. "order_id" => $platform['id'],
  1350. "order_status" => $exam_status,
  1351. ]);
  1352. Db::commit();
  1353. return app_show(0,"审核成功");
  1354. }else{
  1355. Db::rollback();
  1356. return error_show(1004,"审核失败");
  1357. }
  1358. }else{
  1359. Db::rollback();
  1360. return error_show(1004,"审核失败");
  1361. }
  1362. }catch (\Exception $e){
  1363. Db::rollback();
  1364. return error_show(1004,$e->getMessage());
  1365. }
  1366. }
  1367. //财务定价
  1368. public function editladder(){
  1369. $skuCode = isset($this->post['skuCode'])&&$this->post['skuCode']!==""?trim($this->post['skuCode']):"";
  1370. if($skuCode===""){
  1371. return error_show(1004,"参数skuCode不能为空");
  1372. }
  1373. $platform = Db::name("good_platform")->where(["skuCode"=>$skuCode,"is_del"=>0])->find();
  1374. if($platform==false){
  1375. return error_show(1004,"未找到数据");
  1376. }
  1377. $good_ladder = isset($this->post['good_ladder'])&&!empty($this->post['good_ladder'])?$this->post['good_ladder']:"";
  1378. if($good_ladder==""){
  1379. return error_show(1004,"参数good_ladder不能为空");
  1380. }
  1381. $proof_type = isset($this->post['proof_type'])&&$this->post['proof_type']!==""?intval($this->post['proof_type']):"";
  1382. if($proof_type===""){
  1383. return error_show(1004,"参数proof_type不能为空");
  1384. }
  1385. $proof_url = isset($this->post['proof_url'])&&$this->post['proof_url']!==""?trim($this->post['proof_url']):"";
  1386. if($proof_url===""){
  1387. return error_show(1004,"参数proof_url不能为空");
  1388. }
  1389. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1390. if($token==''){
  1391. return error_show(105,"参数token不能为空");
  1392. }
  1393. $user =GetUserInfo($token);
  1394. if(empty($user)||$user['code']!=0){
  1395. return error_show(1002,"用户数据不存在");
  1396. }
  1397. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1398. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1399. $bifore=$platform['exam_status'];
  1400. $platform['exam_status']=4;
  1401. $platform['updatetime']=date("Y-m-d H:i:s");
  1402. Db::startTrans();
  1403. try {
  1404. foreach ($good_ladder as $value){
  1405. $lemp=[];
  1406. isset($value["id"])&&$value["id"]!=""?$lemp['id']=$value['id']:"";
  1407. $lemp['skuCode']=$skuCode;
  1408. $lemp['min_num'] = $value['min_num'];
  1409. $lemp['max_num'] = 0;
  1410. $lemp['sale_price'] = $value['sale_price'];
  1411. $lemp['market_price'] = $value['market_price'];
  1412. $lemp['market_platform'] = $value['market_platform'];
  1413. $lemp['cost_fee'] = $value['cost_fee'];
  1414. $lemp['status'] = $value['status'];
  1415. $lemp['is_del'] = isset($value['is_del'])?$value['is_del']:0;
  1416. isset($value["id"])&&$value["id"]!=""?"": $lemp['addtime'] = date("Y-m-d H:i:s");
  1417. $lemp['updatetime'] =date("Y-m-d H:i:s");
  1418. $count = Db::name("good_ladder")->save($lemp);
  1419. if($count==false){
  1420. Db::rollback();
  1421. return app_show(1004,"商品起订价修改失败");
  1422. }
  1423. }
  1424. $up = Db::name("good_platform")->save($platform);
  1425. if($up){
  1426. ActionLog::logAdd($this->post['token'], [
  1427. "order_code" =>$platform['skuCode'],//咨询单详情编号
  1428. "status" =>$bifore,//这里的status是之前的值
  1429. "action_remark" => '',//备注
  1430. "action_type" => "edit"//新建create,编辑edit,更改状态status
  1431. ], "SPSX", $platform['exam_status'],$platform);
  1432. ProcessOrder::AddProcess($this->post['token'], [
  1433. "order_type" => 'SPSX',
  1434. "order_code" =>$platform['skuCode'],//咨询单详情编号
  1435. "order_id" => $platform['id'],
  1436. "order_status" => $platform['exam_status']
  1437. ]);
  1438. $proof=[
  1439. 'spuCode'=>$platform['spuCode'],
  1440. 'proof_type'=>$proof_type,
  1441. 'proof_url'=>$proof_url,
  1442. 'is_del'=>0,
  1443. "creater"=>$creater,
  1444. "createrid"=>$createrid,
  1445. "addtime"=>date("Y-m-d H:i:s"),
  1446. "updatetime"=>date("Y-m-d H:i:s")
  1447. ];
  1448. $inproof = Db::name("good_proof")->insert($proof);
  1449. if($inproof==false){
  1450. Db::rollback();
  1451. return app_show(1004,"商品凭证新建失败");
  1452. }
  1453. $data=[
  1454. "code"=>$platform['skuCode'],
  1455. "type"=>2,
  1456. "exam_status"=>4,
  1457. "exam_id"=>$createrid,
  1458. "exam_name"=>$creater,
  1459. "exam_remark"=>'',
  1460. "addtime"=>date("Y-m-d H:i:s")
  1461. ];
  1462. $inr=Db::name("good_exam")->insert($data);
  1463. if($inr){
  1464. Db::commit();
  1465. return app_show(0,"审核成功");
  1466. }else{
  1467. Db::rollback();
  1468. return error_show(1004,"审核失败");
  1469. }
  1470. }else{
  1471. Db::rollback();
  1472. return error_show(1004,"审核失败");
  1473. }
  1474. }catch (\Exception $e){
  1475. Db::rollback();
  1476. return error_show(1004,$e->getMessage());
  1477. }
  1478. }
  1479. public function prooflist(){
  1480. $page = isset($this->post['page']) && $this->post['page'] !==""? intval($this->post['page']):"1";
  1481. $size = isset($this->post['size']) && $this->post['size'] !==""? intval($this->post['size']):"10";
  1482. $where =[["is_del","=",0]];
  1483. $spuCode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):"";
  1484. if($spuCode!==""){
  1485. $where[]=["spuCode","like","%$spuCode%"];
  1486. }
  1487. $count = Db::name("good_proof")->where($where)->count();
  1488. $total = ceil($count / $size);
  1489. $page = $page >= $total ? $total : $page;
  1490. $data = Db::name("good_proof")->where($where)->page($page,$size)->order("addtime desc")->select();
  1491. return app_show(0,"获取成功",['list'=>$data,"count"=>$count]);
  1492. }
  1493. /**
  1494. *
  1495. */
  1496. public function againOnline(){
  1497. $skuCode = isset($this->post['skuCode'])&&$this->post['skuCode']!==""?trim($this->post['skuCode']):"";
  1498. if($skuCode===""){
  1499. return error_show(1004,"参数skuCode不能为空");
  1500. }
  1501. $platform = Db::name("good_platform")->where(["skuCode"=>$skuCode,"is_del"=>0])->find();
  1502. if($platform==false){
  1503. return error_show(1004,"未找到数据");
  1504. }
  1505. if($platform["exam_status"]!=7&&$platform["exam_status"]!=8){
  1506. return error_show(1004,"商品状态有误");
  1507. }
  1508. $nake =Db::name("good_nake")->where(["spuCode"=>$platform['spuCode'],"is_del"=>0])->select()->toArray();
  1509. $bifore=$platform['exam_status'];
  1510. $platform['exam_status'] = empty($nake)?1:2;
  1511. $platform['updatetime'] = date("Y-m-d H:i:s");
  1512. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1513. if($token==''){
  1514. return error_show(105,"参数token不能为空");
  1515. }
  1516. $user =GetUserInfo($token);
  1517. if(empty($user)||$user['code']!=0){
  1518. return error_show(1002,"用户数据不存在");
  1519. }
  1520. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1521. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1522. Db::startTrans();
  1523. try {
  1524. $save =Db::name("good_platform")->save($platform);
  1525. if($save){
  1526. ActionLog::logAdd($this->post['token'], [
  1527. "order_code" =>$platform['skuCode'],//咨询单详情编号
  1528. "status" =>$bifore,//这里的status是之前的值
  1529. "action_remark" => '',//备注
  1530. "action_type" => "edit"//新建create,编辑edit,更改状态status
  1531. ], "SPSX", $platform['exam_status'],$platform);
  1532. ProcessOrder::AddProcess($this->post['token'], [
  1533. "order_type" => 'SPSX',
  1534. "order_code" =>$platform['skuCode'],//咨询单详情编号
  1535. "order_id" => $platform['id'],
  1536. "order_status" => $platform['exam_status']
  1537. ]);
  1538. $data=[
  1539. "code"=>$platform['skuCode'],
  1540. "type"=>2,
  1541. "exam_status"=>$platform['exam_status'] ,
  1542. "exam_id"=>$createrid,
  1543. "exam_name"=>$creater,
  1544. "exam_remark"=>'',
  1545. "addtime"=>date("Y-m-d H:i:s")
  1546. ];
  1547. $inr=Db::name("good_exam")->insert($data);
  1548. if($inr){
  1549. Db::commit();
  1550. return app_show(0,"审核成功");
  1551. }
  1552. }
  1553. Db::rollback();
  1554. return error_show(1004,"审核失败");
  1555. }catch (\Exception $e){
  1556. Db::rollback();
  1557. return error_show(1004,$e->getMessage());
  1558. }
  1559. }
  1560. public function copy(){
  1561. $supcode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):"";
  1562. if($supcode==""){
  1563. return error_show(1004,"参数spuCode不能为空");
  1564. }
  1565. $data = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->find();
  1566. if($data==false){
  1567. return error_show(1004,"未找到商品数据");
  1568. }
  1569. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1570. if($token==''){
  1571. return error_show(105,"参数token不能为空");
  1572. }
  1573. $user =GetUserInfo($token);
  1574. if(empty($user)||$user['code']!=0){
  1575. return error_show(102,"用户数据不存在");
  1576. }
  1577. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1578. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1579. $nake = Db::name("good_nake")->where(["spuCode"=>$supcode,"is_del"=>0])->select()->toArray();
  1580. $ladd=[];
  1581. $newCode =makeNo("SKU");
  1582. if(!empty($nake)){
  1583. foreach ($nake as $value){
  1584. $tmp=[];
  1585. $tmp['spuCode']=$newCode;
  1586. $tmp['min_num']=$value['min_num'];
  1587. $tmp['nake_fee'] = $value['nake_fee'];
  1588. $tmp['cost_fee'] = $value['cost_fee'];
  1589. $tmp['delivery_fee'] = $value['delivery_fee'];
  1590. $tmp['cert_fee'] = $value['cert_fee'];
  1591. $tmp['mark_fee'] = $value['mark_fee'];
  1592. $tmp['package_fee'] = $value['package_fee'];
  1593. $tmp['other_fee'] = $value['other_fee'];
  1594. $tmp['nake_total'] =$value['nake_total'];
  1595. $tmp['creater_id']=$createrid;
  1596. $tmp['creater']=$creater;
  1597. $tmp['is_del']=$value['is_del'];
  1598. $tmp['addtime']=date("Y-m-d H:i:s");
  1599. $tmp['updatetime']=date("Y-m-d H:i:s");
  1600. $ladd[]=$tmp;
  1601. }
  1602. }
  1603. $spec = Db::name("good_spec")->where(["spuCode"=>$supcode,"is_del"=>0])->select()->toArray();
  1604. $specArr=[];
  1605. if(!empty($spec)){
  1606. foreach ($spec as $value){
  1607. $tmp=[];
  1608. $tmp['spuCode']=$newCode;
  1609. $tmp['spec_id']=$value['spec_id'];
  1610. $tmp['spec_value_id']=$value['spec_value_id'];
  1611. $tmp['is_del']=$value['is_del'];
  1612. $tmp['addtime']=date("Y-m-d H:i:s");
  1613. $tmp['updatetime']=date("Y-m-d H:i:s");
  1614. $specArr[]=$tmp;
  1615. }
  1616. }
  1617. Db::startTrans();
  1618. try {
  1619. unset($data['id']);
  1620. $data['spuCode']=$newCode;
  1621. $data['createrid']=$createrid;
  1622. $data['creater']=$creater;
  1623. $data['status']=7;
  1624. $data['addtime']=date("Y-m-d H:i:s");
  1625. $data['updatetime']=date("Y-m-d H:i:s");
  1626. $cre = Db::name("good_basic")->insert($data);
  1627. if($cre){
  1628. //修改状态,添加待办
  1629. ActionLog::logAdd($this->post['token'], [
  1630. "order_code" =>$newCode,//咨询单详情编号
  1631. "status" => 0,//这里的status是之前的值
  1632. "action_remark" => '',//备注
  1633. "action_type" => "create"//新建create,编辑edit,更改状态status
  1634. ], "SPCB", 7,$data);
  1635. ProcessOrder::AddProcess($this->post['token'], [
  1636. "order_type" => 'SPCB',
  1637. "order_code" =>$newCode,//咨询单详情编号
  1638. "order_id" => Db::name("good_basic")->getLastInsID(),
  1639. "order_status" =>7
  1640. ]);
  1641. if(!empty($ladd)){
  1642. $na = Db::name("good_nake")->insertAll($ladd);
  1643. if($na==0){
  1644. Db::rollback();
  1645. return error_show(1005,"成本数据复制失败");
  1646. }
  1647. }
  1648. if(!empty($specArr)){
  1649. $sp = Db::name("good_spec")->insertAll($specArr);
  1650. if($sp==0){
  1651. Db::rollback();
  1652. return error_show(1005,"规格数据复制失败");
  1653. }
  1654. }
  1655. Db::commit();
  1656. return app_show(0,"复制数据成功",["spuCode"=>$newCode]);
  1657. }else{
  1658. Db::rollback();
  1659. return error_show(1005,"数据复制失败");
  1660. }
  1661. }catch (\Exception $e){
  1662. Db::rollback();
  1663. return error_show(1004,$e->getMessage());
  1664. }
  1665. }
  1666. public function edit(){
  1667. $supcode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):"";
  1668. if($supcode==""){
  1669. return error_show(1004,"参数spuCode不能为空");
  1670. }
  1671. $data = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->find();
  1672. if($data==false){
  1673. return error_show(1004,"未找到商品数据");
  1674. }
  1675. if ($data['status'] != 6 && $data['status'] != 7 && $data['status'] != 8) {
  1676. return error_show(1004,"商品状态有误");
  1677. }
  1678. $good_name= isset($this->post['good_name'])&&$this->post['good_name']!="" ? trim($this->post['good_name']):"";
  1679. if($good_name==""){
  1680. return error_show(1004,"商品名称不能为空");
  1681. }
  1682. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? intval($this->post['cat_id']):"";
  1683. if($cat_id==''){
  1684. return error_show(1004,"商品分类不能为空");
  1685. }
  1686. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"0";
  1687. // if($brandid==''){
  1688. // return error_show(1004,"商品品牌不能为空");
  1689. // }
  1690. $unit = isset($this->post['unit'])&&$this->post['unit']!=""? trim($this->post['unit']):"";
  1691. if($unit==''){
  1692. return error_show(1004,"商品单位不能为空");
  1693. }
  1694. $good_type = isset($this->post['good_type'])&&$this->post['good_type']!==""? intval($this->post['good_type'])
  1695. :"";
  1696. if($good_type===''){
  1697. return error_show(1004,"参数good_type不能为空");
  1698. }
  1699. $moq=0;
  1700. $customized=0;
  1701. if($good_type==1){
  1702. $moq = isset($this->post['moq'])&&$this->post['moq']!==""? intval($this->post['moq']):"";
  1703. if($moq===''){
  1704. return error_show(1004,"定制商品起订量不能为空");
  1705. }
  1706. $customized = isset($this->post['customized'])&&$this->post['customized']!==""? intval($this->post['customized']):"";
  1707. if($customized===''){
  1708. return error_show(1004,"参数customized不能为空");
  1709. }
  1710. }
  1711. $is_exclusive = isset($this->post['is_exclusive'])&&$this->post['is_exclusive']!==""? intval($this->post['is_exclusive']):"";
  1712. if($is_exclusive===''){
  1713. return error_show(1004,"参数is_exclusive不能为空");
  1714. }
  1715. // $customized = isset($this->post['customized'])&&$this->post['customized']!==""? intval($this->post['customized']):"";
  1716. // if($customized===''){
  1717. // return error_show(1004,"参数customized不能为空");
  1718. // }
  1719. $tax = isset($this->post['tax'])&&$this->post['tax']!==""? intval($this->post['tax']):"";
  1720. if($tax===''){
  1721. return error_show(1004,"参数tax不能为空");
  1722. }
  1723. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
  1724. if($supplierNo==''){
  1725. return error_show(1004,"参数supplierNo不能为空");
  1726. }
  1727. $good_size = isset($this->post['good_size'])&&$this->post['good_size']!=""? trim($this->post['good_size'])
  1728. :"";
  1729. if($good_size==''){
  1730. return error_show(1004,"参数good_size不能为空");
  1731. }
  1732. $company_id = isset($this->post['companyNo'])&&$this->post['companyNo']!=""? trim($this->post['companyNo'])
  1733. :"";
  1734. if($company_id==''){
  1735. return error_show(1004,"参数companyNo不能为空");
  1736. }
  1737. $is_auth = isset($this->post['is_auth'])&&$this->post['is_auth']!==""? intval($this->post['is_auth']):"";
  1738. if($is_auth===''){
  1739. return error_show(1004,"参数is_auth不能为空");
  1740. }
  1741. $auth_img = isset($this->post['auth_img'])&&$this->post['auth_img']!=""? trim($this->post['auth_img']):"";
  1742. // if($auth_img==''){
  1743. // return error_show(1004,"商品不能为空");
  1744. // }
  1745. $after_sales = isset($this->post['after_sales'])&&$this->post['after_sales']!=""? trim($this->post['after_sales']):"";
  1746. if($after_sales==""){
  1747. return error_show(1004,"参数after_sales不能为空");
  1748. }
  1749. $craft_desc = isset($this->post['craft_desc'])&&$this->post['craft_desc']!=""? trim($this->post['craft_desc']):"";
  1750. $good_remark = isset($this->post['good_remark'])&&$this->post['good_remark']!=""? trim($this->post['good_remark']):"";
  1751. if($good_remark===""){
  1752. return error_show(1004,"参数good_remark不能为空");
  1753. }
  1754. $weight = isset($this->post['weight'])&&$this->post['weight']!==""? floatval($this->post['weight']):"";
  1755. if($weight===""){
  1756. return error_show(1004,"参数weight不能为空");
  1757. }
  1758. $packing_way = isset($this->post['packing_way'])&&$this->post['packing_way']!==""? trim($this->post['packing_way']):"";
  1759. if($packing_way===""){
  1760. return error_show(1004,"参数packing_way不能为空");
  1761. }
  1762. $packing_size = isset($this->post['packing_size'])&&$this->post['packing_size']!==""? trim($this->post['packing_size']):"";
  1763. if($packing_size===""){
  1764. return error_show(1004,"参数packing_size不能为空");
  1765. }
  1766. $packing_spec = isset($this->post['packing_spec'])&&$this->post['packing_spec']!==""? trim($this->post['packing_spec']):"";
  1767. if($packing_spec===""){
  1768. return error_show(1004,"参数packing_spec不能为空");
  1769. }
  1770. $packing_weight = isset($this->post['packing_weight'])&&$this->post['packing_weight']!==""? floatval($this->post['packing_weight']):"";
  1771. if($packing_weight===""){
  1772. return error_show(1004,"参数packing_weight不能为空");
  1773. }
  1774. $packing_list = isset($this->post['packing_list'])&&$this->post['packing_list']!==""? trim($this->post['packing_list']):"";
  1775. if($packing_list===""){
  1776. return error_show(1004,"参数packing_list不能为空");
  1777. }
  1778. $good_bar = isset($this->post['good_bar'])&&$this->post['good_bar']!==""? trim($this->post['good_bar']):"";
  1779. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  1780. if($supply_area===""){
  1781. return error_show(1004,"参数supply_area不能为空");
  1782. }
  1783. $delivery_place = isset($this->post['delivery_place'])&&$this->post['delivery_place']!==""? $this->post['delivery_place']:"";
  1784. if($delivery_place===""){
  1785. return error_show(1004,"参数delivery_place不能为空");
  1786. }
  1787. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!==""? $this->post['origin_place']:"";
  1788. if($origin_place===""){
  1789. return error_show(1004,"参数origin_place不能为空");
  1790. }
  1791. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!==""? intval($this->post['delivery_day']):"";
  1792. if($delivery_day===""){
  1793. return error_show(1004,"参数delivery_day不能为空");
  1794. }
  1795. $lead_time = isset($this->post['lead_time'])&&$this->post['lead_time']!==""? intval($this->post['lead_time'])
  1796. :"0";
  1797. // if($lead_time===""){
  1798. // return error_show(1004,"参数lead_time不能为空");
  1799. // }
  1800. $sample_day = isset($this->post['sample_day'])&&$this->post['sample_day']!==""? intval($this->post['sample_day']):"0";
  1801. // if($sample_day===""){
  1802. // return error_show(1004,"参数sample_day不能为空");
  1803. // }
  1804. $sample_fee = isset($this->post['sample_fee'])&&$this->post['sample_fee']!==""? floatval($this->post['sample_fee']):"0";
  1805. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""? trim($this->post['good_img']):"";
  1806. if($good_img===""){
  1807. return error_show(1004,"参数good_img不能为空");
  1808. }
  1809. $good_thumb_img = isset($this->post['good_thumb_img'])&&$this->post['good_thumb_img']!==""? trim($this->post['good_thumb_img']):"";
  1810. if($good_thumb_img===""){
  1811. return error_show(1004,"参数good_thumb_img不能为空");
  1812. }
  1813. $good_info_img = isset($this->post['good_info_img'])&&!empty($this->post['good_info_img'])? trim($this->post['good_info_img']):"";
  1814. if($good_info_img===""){
  1815. return error_show(1004,"参数good_info_img不能为空");
  1816. }
  1817. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!==""? floatval($this->post['cert_fee']):"0";
  1818. $packing_fee = isset($this->post['packing_fee'])&&$this->post['packing_fee']!==""? floatval($this->post['packing_fee']):"0";
  1819. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!==""? floatval($this->post['cost_fee']):"0";
  1820. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!==""? floatval($this->post['mark_fee']):"0";
  1821. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!==""? floatval($this->post['demo_fee']):"0";
  1822. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!==""? floatval($this->post['open_fee']):"0";
  1823. $noble_metal = isset($this->post['noble_metal'])&&$this->post['noble_metal']!==""? intval($this->post['noble_metal']):"0";
  1824. $noble_weight = isset($this->post['noble_weight'])&&$this->post['noble_weight']!==""? floatval($this->post['noble_weight']):"0";
  1825. $is_gold_price= isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!==""? intval($this->post['is_gold_price']):"0";
  1826. $market_price = isset($this->post['market_price'])&&$this->post['market_price']!==""? floatval($this->post['market_price']):"";
  1827. $cgd_gold_price = isset($this->post['cgd_gold_price'])&&$this->post['cgd_gold_price']!==""? floatval($this->post['cgd_gold_price']):"0";
  1828. if($market_price===""){
  1829. return error_show(1004,"参数market_price不能为空");
  1830. }
  1831. $nake_price = isset($this->post['nake_price'])&&$this->post['nake_price']!==""? floatval($this->post['nake_price']):"0";
  1832. $config = isset($this->post['config'])&&$this->post['config']!==""? trim($this->post['config']):"";
  1833. $other_config = isset($this->post['other_config'])&&$this->post['other_config']!==""? trim($this->post['other_config']):"";
  1834. $is_diff = isset($this->post['is_diff'])&&$this->post['is_diff']!==""? intval($this->post['is_diff']):"0";
  1835. $is_stock = isset($this->post['is_stock'])&&$this->post['is_stock']!==""? intval($this->post['is_stock']):"0";
  1836. // $is_step = isset($this->post['is_step'])&&$this->post['is_step']!==""? intval($this->post['is_step']):"";
  1837. // if($is_step===""){
  1838. // return error_show(1004,"参数is_step不能为空");
  1839. // }
  1840. $good_ladder = isset($this->post['good_ladder'])&&!empty($this->post['good_ladder'])? $this->post['good_ladder']:"";
  1841. // if($is_step==1 && $good_ladder==""){
  1842. // return error_show(1004,"启用阶梯,阶梯价不能为空");
  1843. // }
  1844. $speclist = isset($this->post['speclist'])&&!empty($this->post['speclist'])? $this->post['speclist']:"";
  1845. Db::startTrans();
  1846. try {
  1847. $temp=[
  1848. "good_name"=>$good_name,
  1849. "cat_id"=>$cat_id,
  1850. 'brand_id'=>$brandid,
  1851. "good_unit"=>$unit,
  1852. "good_type"=>$good_type,
  1853. "companyNo"=>$company_id,
  1854. "moq"=>$moq,
  1855. "is_exclusive"=>$is_exclusive,
  1856. "customized"=>$customized,
  1857. "tax"=>$tax,
  1858. "supplierNo"=>$supplierNo,
  1859. "is_auth"=>$is_auth,
  1860. "good_size"=>$good_size,
  1861. "auth_img"=>$auth_img,
  1862. "after_sales"=>$after_sales,
  1863. "craft_desc"=>$craft_desc,
  1864. "good_remark"=>$good_remark,
  1865. "weight"=>$weight,
  1866. "packing_way"=>$packing_way,
  1867. "packing_size"=>$packing_size,
  1868. "packing_spec"=>$packing_spec,
  1869. "packing_list"=>$packing_list,
  1870. "packing_weight"=>$packing_weight,
  1871. "good_bar"=>$good_bar,
  1872. "supply_area"=>$supply_area,
  1873. "delivery_place"=>$delivery_place,
  1874. "origin_place"=>$origin_place,
  1875. "delivery_day"=>$delivery_day,
  1876. "lead_time"=>$lead_time,
  1877. "sample_day"=>$sample_day,
  1878. "sample_fee"=>$sample_fee,
  1879. "good_img"=>$good_img,
  1880. "good_thumb_img"=>$good_thumb_img,
  1881. "good_info_img"=>$good_info_img,
  1882. "cert_fee"=>$cert_fee,
  1883. "packing_fee"=>$packing_fee,
  1884. "is_diff"=>$is_diff,
  1885. "config"=>$config,
  1886. "other_config"=>$other_config,
  1887. "is_stock"=>$is_stock,
  1888. "cost_fee"=>$cost_fee,
  1889. "mark_fee"=>$mark_fee,
  1890. "demo_fee"=>$demo_fee,
  1891. "open_fee"=>$open_fee,
  1892. "noble_metal"=>$noble_metal,
  1893. "noble_weight"=>$noble_weight,
  1894. "is_gold_price"=>$is_gold_price,
  1895. "market_price"=>$market_price,
  1896. "nake_price"=>$nake_price,
  1897. "cgd_gold_price"=>$cgd_gold_price,
  1898. "is_step" => count($good_ladder) > 1 ? 1 : 0,
  1899. "status"=>"0",
  1900. "updatetime"=>date("Y-m-d H:i:s")
  1901. ];
  1902. $field = array_diff_assoc($temp,$data);
  1903. $temp['field_change'] =empty($field)?"":json_encode(array_keys($field));
  1904. $up = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->save($temp);
  1905. $var = array_diff($temp,$data);
  1906. $json = json_encode($var,JSON_UNESCAPED_UNICODE);
  1907. $dat = json_encode($data,JSON_UNESCAPED_UNICODE);
  1908. if($up){
  1909. ChangeLog::logAdd(3,$data['spuCode'],$dat,$json,$this->post['token'],$this->post);
  1910. //修改状态,添加待办
  1911. ActionLog::logAdd($this->post['token'], [
  1912. "order_code" =>$supcode,//咨询单详情编号
  1913. "status" => $data['status'],//这里的status是之前的值
  1914. "action_remark" => '',//备注
  1915. "action_type" => "create"//新建create,编辑edit,更改状态status
  1916. ], "SPCB", 0,$temp);
  1917. ProcessOrder::AddProcess($this->post['token'], [
  1918. "order_type" => 'SPCB',
  1919. "order_code" =>$supcode,//咨询单详情编号
  1920. "order_id" => $data['id'],
  1921. "order_status" =>0
  1922. ]);
  1923. if($speclist!=="" && !empty($speclist)){
  1924. foreach ($speclist as $value){
  1925. $lemp=[];
  1926. isset($value["id"])&&$value["id"]!=''?$lemp['id']=$value['id']:"";
  1927. $lemp['spuCode']=$supcode;
  1928. $lemp['spec_id'] = $value['spec_id'];
  1929. $lemp['spec_value_id'] = $value['spec_value_id'];
  1930. $lemp['is_del'] = isset($value['is_del'])?$value['is_del']:0;
  1931. isset($value["id"])&&$value["id"]!=''?"": $lemp['addtime'] = date("Y-m-d H:i:s");
  1932. $lemp['updatetime'] =date("Y-m-d H:i:s");
  1933. $count = Db::name("good_spec")->save($lemp);
  1934. if($count==false){
  1935. Db::rollback();
  1936. return app_show(1004,"商品规格值修改失败");
  1937. }
  1938. }
  1939. }
  1940. if($good_ladder!=="" && !empty($good_ladder)){
  1941. $user =GetUserInfo($this->post['token']);//获取用户信息,下面更新成本表的创建人
  1942. $top_cat_id = made($cat_id);//获取所有分类
  1943. $top_cat_id = isset($top_cat_id[0]['id']) ? $top_cat_id[0]['id'] : 0;//获取顶级分类id
  1944. foreach ($good_ladder as $value){
  1945. $lemp=[];
  1946. isset($value["id"])&&$value["id"]!=''?$lemp['id']=$value['id']:"";
  1947. $lemp['spuCode']=$supcode;
  1948. $lemp['min_num'] = $value['min_num'];
  1949. $lemp['nake_fee'] = $value['nake_fee'];
  1950. $lemp['cost_fee'] = $value['cost_fee'];
  1951. $lemp['delivery_fee'] = $value['delivery_fee'];
  1952. $lemp['cert_fee'] = $value['cert_fee'];
  1953. $lemp['mark_fee'] = $value['mark_fee'];
  1954. $lemp['package_fee'] = $value['package_fee'];
  1955. $lemp['other_fee'] = $value['other_fee'];
  1956. if ($is_gold_price == 1 && $top_cat_id == 6) {
  1957. // $gold =Db::name("gold_price1")->where(["type"=>$noble_metal,"status"=>1,"is_del"=>0])
  1958. // ->order("addtime desc")->find();
  1959. //$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'];
  1960. //成本合计=贵金属重量*供应商采购金价 + 工艺费*贵金属重量+加标费+包装费+证书费+成本裸价+运费+其他费用
  1961. //成本总计启用实时金价时,采用供应商实时金价
  1962. $lemp['nake_total'] =$noble_weight *$cgd_gold_price+ $value['cost_fee'] * $noble_weight +
  1963. $value['mark_fee'] + $value['package_fee'] + $value['cert_fee'] + $value['nake_fee'] + $value['delivery_fee'] + $value['other_fee'];
  1964. }else{
  1965. $lemp['nake_total'] =$value['nake_fee']+$value['delivery_fee']+$value['cert_fee']+$value['mark_fee']+$value['package_fee']+$value['other_fee'];
  1966. }
  1967. $lemp['creater_id'] = isset($user["data"]['id']) ? $user["data"]['id'] : 0;
  1968. $lemp['creater'] = isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1969. $lemp['is_del'] = isset($value['is_del'])?$value['is_del']:0;
  1970. isset($value["id"])&&$value["id"]!=''?"": $lemp['addtime'] = date("Y-m-d H:i:s");
  1971. $lemp['updatetime'] =date("Y-m-d H:i:s");
  1972. $count = Db::name("good_nake")->save($lemp);
  1973. if($count==false){
  1974. Db::rollback();
  1975. return app_show(1004,"商品规成本修改失败");
  1976. }
  1977. }
  1978. }
  1979. Db::commit();
  1980. return app_show(0,"更新成功");
  1981. }else{
  1982. Db::rollback();
  1983. return error_show(1005,"更新失败");
  1984. }
  1985. }catch (\Exception $e){
  1986. Db::rollback();
  1987. return error_show(1004,$e->getMessage());
  1988. }
  1989. }
  1990. public function checkPrice(){
  1991. $spuCode=isset($this->post['spuCode'])&&$this->post['spuCode']!=""? trim($this->post['spuCode']):"";
  1992. if($spuCode==""){
  1993. return error_show(1005,"参数spuCode不能为空");
  1994. }
  1995. $good =Db::name("good_basic")->where(["spuCode"=>$spuCode,"is_del"=>0])->find();
  1996. if($good==false){
  1997. return error_show(1005,"商品数据未找到");
  1998. }
  1999. $num=isset($this->post['min_num'])&&$this->post['min_num']!=="" ? intval($this->post['min_num']):"";
  2000. if($num==""){
  2001. return error_show(1005,"参数min_num不能为空");
  2002. }
  2003. $nakelist = Db::name("good_nake")->where(['spuCode'=>$spuCode,"is_del"=>0])->where([["min_num","<=",$num]])
  2004. ->order("min_num desc")->find();
  2005. if($nakelist==false){
  2006. $nakelist = Db::name("good_nake")->where(['spuCode'=>$spuCode,"is_del"=>0])->order("min_num asc")->find();
  2007. return error_show(1010,"起订量不足{$nakelist['min_num']}");
  2008. }
  2009. $catinfo = Db::name("cat")->where(["id"=>$good['cat_id']])->find();
  2010. $budget = isset($catinfo['sale_rate']) ? $catinfo['sale_rate']/100:0;
  2011. $top_cat_id = made($catinfo['id']);//获取所有分类
  2012. $top_cat_id = isset($top_cat_id[0]['id']) ? $top_cat_id[0]['id'] : 0;//获取顶级分类id
  2013. $sale_cost_fee = 0;
  2014. if ($good['is_gold_price'] == 1 && $top_cat_id == 6) {
  2015. // $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'];
  2016. //系统售价=(贵金属重量*供应商采购金价 + 工艺费*贵金属重量+加标费+包装费+证书费+成本裸价+运费+其他费用)/(1-成本售价/100)
  2017. $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);
  2018. //计算工艺费
  2019. //销售工艺费=(( 商品重量* 供应商采购金价 + 采购成本工艺费* 商品重量+包装费+加标费+证书费+产品裸价+其他费用)/(1-成本售价/100)-(包装费+加标费+证书费+产品裸价0+运费+其他费用) )/商品重量-供应商采购金价
  2020. $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"];
  2021. }else{
  2022. $saleprice = ($nakelist['mark_fee'] + $nakelist['package_fee'] + $nakelist['cert_fee'] + $nakelist['delivery_fee'] + $nakelist['nake_fee']) / (1 - $budget);
  2023. }
  2024. return app_show(0, "获取成功", ["sale_price" => round($saleprice, 2), 'new_cost_fee' => round($sale_cost_fee, 2)]);
  2025. }
  2026. //咨询成交商品池 添加上线商品
  2027. public function onlineZixunGoods()
  2028. {
  2029. $param = $this->request->only(['platform', 'codes', 'online_reason', 'online_remark', 'token'], 'post', 'trim');
  2030. $val = Validate::rule([
  2031. 'platform|所选上线平台' => 'require|number|gt:0',
  2032. 'codes|所选上线商品编号' => 'require',
  2033. 'online_reason|上线原因' => 'require',
  2034. 'online_remark|上线备注' => 'require',
  2035. 'token' => 'require',
  2036. ]);
  2037. if (!$val->check($param)) return error_show(1004, $val->getError());
  2038. $good_zixun_list = Db::name("good_zixun")
  2039. ->where(["is_del" => 0])
  2040. ->whereIn('spuCode', $param['codes'])
  2041. ->column('*', 'spuCode');
  2042. if (empty($good_zixun_list)) return error_show(1004, "未找到相关咨询商品数据");
  2043. $a = array_diff($param['codes'], array_keys($good_zixun_list));
  2044. if (!empty($a)) return error_show(1005, '该咨询商品不存在' . implode(',', $a));
  2045. $isonline = Db::name("good_platform")
  2046. ->alias('gp')
  2047. ->field('gp.id,gp.spuCode,gb.good_name,gb.good_img,gp.exam_status')
  2048. ->where(["gp.platform_code" => $param['platform'], "gp.is_del" => 0])
  2049. ->whereIn('gp.spuCode', $param['codes'])
  2050. ->leftJoin('good_basic gb', 'gb.spuCode=gp.spuCode AND gb.is_del=0')
  2051. ->select()
  2052. ->toArray();
  2053. if (!empty($isonline)) {
  2054. foreach ($isonline as &$v) {
  2055. $spec = Db::name("good_spec")
  2056. ->where(["spuCode" => $v['spuCode'], "is_del" => 0])
  2057. ->select()
  2058. ->toArray();
  2059. $speclist = [];
  2060. if (!empty($spec)) {
  2061. foreach ($spec as $val) {
  2062. $temp = [];
  2063. $temp['id'] = $val['id'];
  2064. $temp['spuCode'] = $val['spuCode'];
  2065. $temp['spec_id'] = $val['spec_id'];
  2066. $temp['spec_value_id'] = $val['spec_value_id'];
  2067. $temp['is_del'] = $val['is_del'];
  2068. $sp = Db::name("specs")->where(["id" => $val['spec_id']])->find();
  2069. $temp['spec_name'] = isset($sp["spec_name"]) ? $sp["spec_name"] : "";
  2070. $spv = Db::name("spec_value")->where(["id" => $val['spec_value_id']])->find();
  2071. $temp['spec_value'] = isset($spv["spec_value"]) ? $spv["spec_value"] : "";
  2072. $speclist[] = $temp;
  2073. }
  2074. }
  2075. $v["speclist"] = empty($speclist) ? [] : $speclist;
  2076. }
  2077. return app_show(1009, "存在已上线产品", $isonline);
  2078. }
  2079. if (!empty($isonline)) return error_show(1005, $isonline['spuCode'] . '该商品已在商品成本管理中,请在商品成本管理菜单提交上线!');
  2080. $user = GetUserInfo($param['token']);
  2081. if (empty($user) || $user['code'] != 0) return error_show(1002, "用户数据不存在");
  2082. $createrid = isset($user["data"]['id']) ? $user["data"]['id'] : "";
  2083. $creater = isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  2084. $data = $good_insert_data = $good_basic_insert_data = $good_spec_insert_data = [];
  2085. $i = 0;
  2086. $all_nakes = Db::name("good_nake")
  2087. ->where(["is_del" => 0])->fetchSql()
  2088. ->whereIn('spuCode', $param['codes'])
  2089. ->group('spuCode')
  2090. ->column('count(`id`) total', 'spuCode');
  2091. $all_good = Db::name('good')
  2092. ->where('is_del', 0)
  2093. ->whereIn('spuCode', $param['codes'])
  2094. ->column('id', 'spuCode');
  2095. if (!empty($all_good)) return error_show(1004, '请从商品成本提交该商品上线');
  2096. $all_good_basic = Db::name('good_basic')
  2097. ->where('is_del', 0)
  2098. ->whereIn('spuCode', $param['codes'])
  2099. ->column('id', 'spuCode');
  2100. if (!empty($all_good_basic)) return error_show(1004, '请从商品成本提交该商品上线');
  2101. foreach ($param['codes'] as $value) {
  2102. //改变编码规则,将原来的skuCode后两位换成序列号
  2103. //str_pad字符串填充
  2104. $skuCode = makeNo("SN");
  2105. $skuCode = substr($skuCode, 0, -2) . str_pad($i, 2, '0', STR_PAD_LEFT);
  2106. $data[] = [
  2107. "spuCode" => $value,
  2108. "skuCode" => $skuCode,
  2109. "platform_code" => $param['platform'],
  2110. "online_reason" => $param['online_reason'],
  2111. "online_remark" => $param['online_remark'],
  2112. "exam_status" => isset($all_nakes[$value]) ? ($all_nakes[$value] > 0 ? 2 : 1) : 1,
  2113. "is_online" => 0,
  2114. "status" => 0,
  2115. "is_del" => 0,
  2116. "creater" => $creater,
  2117. "createrid" => $createrid,
  2118. "addtime" => date("Y-m-d H:i:s"),
  2119. "updatetime" => date("Y-m-d H:i:s")
  2120. ];
  2121. //good表
  2122. if (!isset($all_good[$value])) {
  2123. $good_insert_data[] = [
  2124. 'spuCode' => $good_zixun_list[$value]['spuCode'],
  2125. 'good_code' => $good_zixun_list[$value]['good_code'],
  2126. 'good_name' => $good_zixun_list[$value]['good_name'],
  2127. 'cat_id' => $good_zixun_list[$value]['cat_id'],
  2128. 'brand_id' => $good_zixun_list[$value]['brand_id'],
  2129. 'good_unit' => $good_zixun_list[$value]['good_unit'],
  2130. 'good_type' => $good_zixun_list[$value]['good_type'],
  2131. 'companyNo' => $good_zixun_list[$value]['companyNo'],
  2132. 'moq' => $good_zixun_list[$value]['moq'],
  2133. 'customized' => $good_zixun_list[$value]['customized'],
  2134. 'tax' => $good_zixun_list[$value]['tax'],
  2135. 'supplierNo' => $good_zixun_list[$value]['supplierNo'],
  2136. 'is_auth' => $good_zixun_list[$value]['is_auth'],
  2137. 'is_stock' => '',
  2138. 'auth_img' => $good_zixun_list[$value]['auth_img'],
  2139. 'after_sales' => '',
  2140. 'craft_desc' => $good_zixun_list[$value]['craft_desc'],
  2141. 'good_remark' => $good_zixun_list[$value]['good_remark'],
  2142. 'good_size' => '',
  2143. 'weight' => $good_zixun_list[$value]['weight'],
  2144. 'packing_way' => '',
  2145. 'packing_size' => '',
  2146. 'packing_spec' => '',
  2147. 'packing_list' => '',
  2148. 'packing_weight' => '',
  2149. 'good_bar' => '',
  2150. 'supply_area' => $good_zixun_list[$value]['supply_area'],
  2151. 'delivery_place' => '',
  2152. 'origin_place' => '',
  2153. 'delivery_day' => 0,
  2154. 'lead_time' => '',
  2155. 'sample_day' => '',
  2156. 'sample_fee' => '',
  2157. 'good_img' => $good_zixun_list[$value]['good_img'],
  2158. 'good_thumb_img' => $good_zixun_list[$value]['good_thumb_img'],
  2159. 'good_info_img' => $good_zixun_list[$value]['good_info_img'],
  2160. 'cert_fee' => '',
  2161. 'packing_fee' => '',
  2162. 'cost_fee' => '',
  2163. 'mark_fee' => '',
  2164. 'demo_fee' => '',
  2165. 'open_fee' => '',
  2166. 'noble_metal' => $good_zixun_list[$value]['noble_metal'],
  2167. 'noble_weight' => $good_zixun_list[$value]['good_weight'],
  2168. 'is_gold_price' => $good_zixun_list[$value]['is_gold_price'],
  2169. 'cgd_gold_price' => '',
  2170. 'market_price' => '',
  2171. 'nake_price' => '',
  2172. 'is_step' => '',
  2173. 'is_online' => '',
  2174. 'status' => 1,//待完善成本
  2175. 'createrid' => $createrid,
  2176. 'creater' => $creater,
  2177. 'is_del' => 0,
  2178. 'field_change' => '',
  2179. 'addtime' => date('Y-m-d H:i:s'),
  2180. 'updatetime' => date('Y-m-d H:i:s'),
  2181. 'is_exclusive' => '',
  2182. 'is_diff' => $good_zixun_list[$value]['is_diff'],
  2183. 'config' => $good_zixun_list[$value]['config'],
  2184. 'other_config' => $good_zixun_list[$value]['other_config'],
  2185. ];
  2186. }
  2187. //good_basic表
  2188. if (!isset($all_good_basic[$value])) {
  2189. $good_basic_insert_data[] = [
  2190. 'spuCode' => $good_zixun_list[$value]['spuCode'],
  2191. 'good_code' => $good_zixun_list[$value]['good_code'],
  2192. 'good_name' => $good_zixun_list[$value]['good_name'],
  2193. 'cat_id' => $good_zixun_list[$value]['cat_id'],
  2194. 'brand_id' => $good_zixun_list[$value]['brand_id'],
  2195. 'companyNo' => $good_zixun_list[$value]['companyNo'],
  2196. 'good_unit' => $good_zixun_list[$value]['good_unit'],
  2197. 'good_type' => $good_zixun_list[$value]['good_type'],
  2198. 'moq' => $good_zixun_list[$value]['moq'],
  2199. 'customized' => $good_zixun_list[$value]['customized'],
  2200. 'tax' => $good_zixun_list[$value]['tax'],
  2201. 'supplierNo' => $good_zixun_list[$value]['supplierNo'],
  2202. 'is_auth' => $good_zixun_list[$value]['is_auth'],
  2203. 'auth_img' => $good_zixun_list[$value]['auth_img'],
  2204. 'after_sales' => '',
  2205. 'craft_desc' => $good_zixun_list[$value]['craft_desc'],
  2206. 'good_remark' => $good_zixun_list[$value]['good_remark'],
  2207. 'weight' => $good_zixun_list[$value]['weight'],
  2208. 'packing_way' => '',
  2209. 'packing_size' => '',
  2210. 'packing_spec' => '',
  2211. 'packing_list' => '',
  2212. 'packing_weight' => '',
  2213. 'good_bar' => '',
  2214. 'supply_area' => $good_zixun_list[$value]['supply_area'],
  2215. 'delivery_place' => '',
  2216. 'origin_place' => '',
  2217. 'delivery_day' => '',
  2218. 'lead_time' => '',
  2219. 'sample_day' => '',
  2220. 'sample_fee' => '',
  2221. 'good_img' => '',//$good_zixun_list[$value]['good_img'],
  2222. 'good_thumb_img' => $good_zixun_list[$value]['good_thumb_img'],
  2223. 'good_info_img' => $good_zixun_list[$value]['good_img'],//商品主图对应到商品详情
  2224. 'cert_fee' => '',
  2225. 'packing_fee' => '',
  2226. 'cost_fee' => '',
  2227. 'mark_fee' => '',
  2228. 'demo_fee' => '',
  2229. 'open_fee' => '',
  2230. 'noble_metal' => $good_zixun_list[$value]['noble_metal'],
  2231. 'noble_weight' => $good_zixun_list[$value]['good_weight'],
  2232. 'is_gold_price' => $good_zixun_list[$value]['is_gold_price'],
  2233. 'cgd_gold_price' => '',
  2234. 'market_price' => '',
  2235. 'nake_price' => '',
  2236. 'is_step' => '',
  2237. 'is_online' => '',
  2238. 'status' => 8,//咨询商品待编辑
  2239. 'createrid' => $createrid,
  2240. 'creater' => $creater,
  2241. 'field_change' => '',
  2242. 'is_del' => 0,
  2243. 'addtime' => date('Y-m-d H:i:s'),
  2244. 'updatetime' => date('Y-m-d H:i:s'),
  2245. 'is_diff' => $good_zixun_list[$value]['is_diff'],
  2246. 'config' => $good_zixun_list[$value]['config'],
  2247. 'other_config' => $good_zixun_list[$value]['other_config'],
  2248. ];
  2249. }
  2250. //good_spec
  2251. if (!empty($good_zixun_list[$value]['specinfo'])) {
  2252. $spec_list = json_decode($good_zixun_list[$value]['specinfo'], true);
  2253. foreach ($spec_list as $spec) {
  2254. $temp = Db::name('good_spec')
  2255. ->field('id')
  2256. ->where(['spuCode' => $value, 'spec_id' => $spec['specid'], 'spec_value_id' => $spec['spec_value_id'], 'is_del' => 0])
  2257. ->find();
  2258. if (!empty($temp)) {
  2259. $good_spec_insert_data[] = [
  2260. 'spuCode' => $value,
  2261. 'spec_id' => $spec['specid'],
  2262. 'spec_value_id' => $spec['spec_value_id'],
  2263. 'is_del' => 0,
  2264. 'addtime' => date('Y-m-d H:i:s'),
  2265. 'updatetime' => date('Y-m-d H:i:s'),
  2266. ];
  2267. }
  2268. }
  2269. }
  2270. $i++;
  2271. }
  2272. if (!empty($isonline)) {
  2273. return app_show(1009, "存在已上线产品", $isonline);
  2274. }
  2275. Db::startTrans();
  2276. try {
  2277. $create = Db::name("good_platform")->insertAll($data);
  2278. Db::name("good_zixun")
  2279. ->where(["is_del" => 0, 'status' => 1])
  2280. ->whereIn('spuCode', $param['codes'])
  2281. ->update(['status' => 2, 'updatetime' => date('Y-m-d H:i:s')]);
  2282. if (!empty($good_insert_data)) Db::name('good')->insertAll($good_insert_data);
  2283. if (!empty($good_basic_insert_data)) Db::name('good_basic')->insertAll($good_basic_insert_data);
  2284. if (!empty($good_spec_insert_data)) Db::name('good_spec')->insertAll($good_spec_insert_data);
  2285. if ($create) {
  2286. foreach ($good_basic_insert_data as $value) {
  2287. ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
  2288. "order_code" =>$value['spuCode'],//
  2289. "status" => 8,//待产品审核
  2290. "action_remark" => '',//备注
  2291. "action_type" => "create"//新建create,编辑edit,更改状态status
  2292. ], "SPCB", $value['status'], $value);
  2293. ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
  2294. "order_type" => 'SPCB',
  2295. "order_code" =>$value['spuCode'],//
  2296. "order_id" => isset($value['id']) ? $value['id'] : 0,
  2297. "order_status" => 8,//待产品审核
  2298. ]);
  2299. }
  2300. foreach ($data as $value) {
  2301. ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
  2302. "order_code" =>$value['skuCode'],//
  2303. "status" => 0,//待产品审核
  2304. "action_remark" => '',//备注
  2305. "action_type" => "create"//新建create,编辑edit,更改状态status
  2306. ], "SPSX", $value['exam_status'], $value);
  2307. ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
  2308. "order_type" => 'SPSX',
  2309. "order_code" =>$value['skuCode'],//
  2310. "order_id" => isset($value['id']) ? $value['id'] : 0,
  2311. "order_status" =>$value['exam_status'],//待产品审核
  2312. ]);
  2313. }
  2314. Db::commit();
  2315. return app_show(0, "提交成功");
  2316. } else {
  2317. Db::rollback();
  2318. return error_show(1004, "提交失败");
  2319. }
  2320. } catch (Exception $exception) {
  2321. Db::rollback();
  2322. return error_show(1005, $exception->getMessage());
  2323. }
  2324. }
  2325. }