User.php 97 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237
  1. <?php
  2. namespace app\controller\api\entropybarter;
  3. use alipay\aop\AlipayConfig;
  4. use alipay\aop\AopCertClient;
  5. use alipay\aop\request\AlipayTradePrecreateRequest;
  6. use alipay\aop\request\AlipayFundTransUniTransferRequest;
  7. use crmeb\basic\BaseController;
  8. use Endroid\QrCode\QrCode;
  9. use think\db\Where;
  10. use think\Exception;
  11. use think\facade\Cache;
  12. use think\facade\Db;
  13. use think\App;
  14. class User extends BaseController
  15. {
  16. protected $merId;
  17. protected $source;
  18. /**
  19. * UserExtract constructor.
  20. * @param App $app
  21. */
  22. public function __construct(App $app)
  23. {
  24. parent::__construct($app);
  25. $this->source = $this->request->header('source');
  26. $this->merId = $this->request->header('merId');
  27. }
  28. public function test(){
  29. dump($order_236 = new Order_236());
  30. }
  31. /**
  32. * @param $user
  33. * @param $top_id
  34. * 创建用户
  35. */
  36. public function create($uid,$top_id,$mer_id)
  37. {
  38. // $table_name='rrx_entropy_barter_user_'.$mer_id;
  39. // $exist = Db::query("show tables like '$table_name'");
  40. // if(empty($exist)){
  41. // return '';
  42. // }
  43. // $top_eb_id=Db::name('entropy_barter_user_'.$mer_id)->where('uid',$top_id)->find();
  44. // $insert_data=[
  45. // 'uid'=>$uid,
  46. // 'top_eb_id'=>$top_eb_id['top_eb_id'],
  47. // 'ctime'=>time()
  48. // ];
  49. // Db::name('entropy_barter_user_'.$mer_id)->insert($insert_data);
  50. }
  51. public function xcx_bangding()
  52. {
  53. try {
  54. $param=$this->request->param();
  55. Db::name('log')->insert(['data'=>json_encode($param)]);
  56. Db::name('log')->insert(['data'=>'商品详情绑定推荐关系 进来了']);
  57. $share_id=$this->request->params(['share_id']);
  58. $mer_id=$this->request->params(['mer_id']);
  59. if(!$mer_id['mer_id']){
  60. Db::name('log')->insert(['data'=>'商品详情绑定推荐关系---商户ID 未传']);
  61. }
  62. if(!$share_id['share_id']){
  63. Db::name('log')->insert(['data'=>'商品详情绑定推荐关系---分享ID 未传']);
  64. }
  65. Db::name('log')->insert(['data'=>'商品详情绑定推荐关系--商户ID:'.$mer_id['mer_id']]);
  66. $mer_data=Db::name('merchant')->where('mer_id',$mer_id['mer_id'])->value('merchant_type');
  67. if($mer_data==2){
  68. $uid = $this->request->uid();
  69. Db::name('log')->insert(['data'=>'商品详情绑定推荐关系--用户ID:'.$uid]);
  70. Db::name('log')->insert(['data'=>json_encode($share_id)]);
  71. $spread_uid=Db::name('product_share')->where('id',$share_id['share_id'])->value('uid');
  72. Db::name('log')->insert(['data'=>Db::name('product_share')->getLastSql()]);
  73. if(!$spread_uid){
  74. return app('json')->fail('未查询到分享人的ID');
  75. }
  76. $this->bangding($uid,$spread_uid,$mer_id['mer_id']);
  77. $this->cxb_bangding($uid,$spread_uid);
  78. }
  79. }catch (\Exception $e) {
  80. Db::name('log')->insert(['data'=>'绑定关系错误:'.$e->getFile().':'.$e->getLine().'【'.$e->getMessage().'】']);
  81. }
  82. }
  83. /**
  84. * @param $uid
  85. * @param $spread_uid
  86. * 绑定储蓄保的关系
  87. */
  88. public function cxb_bangding($uid,$spread_uid)
  89. {
  90. $spread_uid_user=Db::name('user')->where('uid',$uid)->value('spread_uid');
  91. Db::name('log')->insert(['data'=>'绑定储蓄保的关系进来了他的上级ID'.$spread_uid_user]);
  92. if($spread_uid_user==0){
  93. Db::name('user')->where('uid',$uid)->update(['spread_uid'=>$spread_uid]);
  94. }
  95. }
  96. /**
  97. *绑定推荐关系
  98. */
  99. public function bangding($uid='',$spread_uid='',$mer_id='')
  100. {
  101. try {
  102. Db::name('log')->insert(['data'=>'进来了User']);
  103. if(!$uid){
  104. $uid = $this->request->uid();
  105. }
  106. if(!$mer_id){
  107. $mer_id=$this->request->params(['mer_id']);
  108. if(empty($mer_id['mer_id'])){
  109. return app('json')->fail('请联系技术人员排查问题,感谢您的反馈');
  110. }else{
  111. $mer_id=$mer_id['mer_id'];
  112. }
  113. }
  114. Db::name('log')->insert(['data'=>'mer_id----'.json_encode($mer_id)]);
  115. $data=Db::name('entropy_barter_user_'.$mer_id)->where('uid',$uid)->find();
  116. if($data){
  117. return app('json')->fail('已绑定推荐关系');
  118. }
  119. $phone=$this->request->params(['phone']);
  120. if(!empty($phone['phone'])||$spread_uid){
  121. if(!$spread_uid){
  122. $spread_uid=Db::name('user')->where('account',$phone['phone'])->value('uid');
  123. }
  124. if(!$spread_uid){
  125. return app('json')->fail('未查询到推荐人信息');
  126. }
  127. $top_eb_id=Db::name('entropy_barter_user_'.$mer_id)->where('uid',$spread_uid)->value('eb_id');
  128. if(!$top_eb_id){
  129. if($mer_id==236){
  130. $top_eb_id='13';
  131. }elseif ($mer_id==276){
  132. $top_eb_id='12';
  133. }elseif ($mer_id=='290'){
  134. $top_eb_id='1';
  135. }elseif ($mer_id=='148'){
  136. $top_eb_id=0;
  137. }
  138. }
  139. }else{
  140. $top_eb_id=Db::name('user')->where('uid',$uid)->value('spread_uid');
  141. $top_eb_id=Db::name('entropy_barter_user_'.$mer_id)->where('uid',$top_eb_id)->value('eb_id');
  142. if(!$top_eb_id){
  143. if($mer_id==236){
  144. $top_eb_id='13';
  145. }elseif ($mer_id==276){
  146. $top_eb_id='12';
  147. }elseif ($mer_id=='290'){
  148. $top_eb_id='1';
  149. }elseif ($mer_id=='148'){
  150. $top_eb_id=0;
  151. }
  152. }
  153. }
  154. $type = 1;
  155. if($mer_id == '290'){
  156. $type = 0;
  157. }
  158. $insert_data=[
  159. 'uid'=>$uid,
  160. 'top_eb_id'=>$top_eb_id,
  161. 'ctime'=>time(),
  162. 'type'=>$type
  163. ];
  164. Db::name('log')->insert(['data'=>'添加数据--'.json_encode($insert_data)]);
  165. if($mer_id!=290){
  166. if($top_eb_id){
  167. $bill=[
  168. 'from_id'=>'0',
  169. 'number'=>30,
  170. 'to_id'=>$top_eb_id,
  171. 'type'=>'1',
  172. 'order_no'=>time(),
  173. 'remarks'=>'邀请好友得30积分',
  174. 'pm'=>1,
  175. 'status'=>2,
  176. 'on_line'=>1,
  177. 'mer_id'=>$mer_id
  178. ];
  179. $this->eb_user_bill($bill);
  180. Db::name('entropy_barter_user_'.$mer_id)->where('eb_id',$top_eb_id)->inc('integral',30)->update();
  181. }
  182. }
  183. $res=Db::name('entropy_barter_user_'.$mer_id)->insertGetId($insert_data);
  184. $insertData=[
  185. 'eb_id'=>$res,
  186. 'key'=>'proportion',
  187. ];
  188. $re=Db::name('entropy_barter_config_user_'.$mer_id)->insert($insertData);
  189. if($res&&$re){
  190. return app('json')->success('绑定成功');
  191. }else{
  192. return app('json')->fail('请联系技术人员排查问题,感谢您的反馈');
  193. }
  194. }catch (Exception $exception){
  195. Db::name("log")->insert(array('data'=>$exception->getFile().':'.$exception->getLine().'【'.$exception->getMessage().'】'));//日志记录
  196. }
  197. }
  198. /*
  199. * 绑定状态
  200. */
  201. public function bangding_status()
  202. {
  203. $uid = $this->request->uid();
  204. $mer_id=$this->request->params(['mer_id']);
  205. if(empty($mer_id['mer_id'])){
  206. return app('json')->fail('请联系技术人员排查问题,感谢您的反馈');
  207. }else{
  208. $mer_id=$mer_id['mer_id'];
  209. }
  210. $data=Db::name('entropy_barter_user_'.$mer_id)->where('uid',$uid)->find();
  211. if($data){
  212. return app('json')->success(['status'=>1]);
  213. }else{
  214. return app('json')->success(['status'=>2]);
  215. }
  216. }
  217. /**12171
  218. * @param $order
  219. * @param $type 1 线上 2线下
  220. * 订单
  221. * 修改用户 类型 比例 完成
  222. */
  223. public function order($order, $type)
  224. {
  225. try {
  226. Db::name('log')->insert(['data'=>'user._______'.json_encode($order)]);
  227. $mer_id=$order['mer_id'];
  228. Db::name('log')->insert(['data'=>'商户id0'.$mer_id]);
  229. if($mer_id=='290'){
  230. return $this->pay_orrder_290($order,$type);
  231. }elseif($mer_id=='236'){
  232. Db::name('log')->insert(['data'=>'商户id1'.$mer_id]);
  233. try {
  234. $order_236=new Order_236();
  235. Db::name('log')->insert(['data'=>'商户id2'.json_encode($order_236)]);
  236. return $order_236-> order($order, $type);
  237. }catch (\Exception $e) {
  238. Db::name('log')->insert(['data'=>'地宝订单支付出错:'.$e->getFile().':'.$e->getLine().'【'.$e->getMessage().'】']);
  239. }
  240. }
  241. }catch (\Exception $e) {
  242. Db::name('log')->insert(['data'=>'地宝订单支付出错lll:'.$e->getFile().':'.$e->getLine().'【'.$e->getMessage().'】']);
  243. }
  244. $user=Db::name('entropy_barter_user_'.$mer_id)->where('uid',$order['uid'])->find();
  245. $update=[];
  246. $update_config=[];
  247. //增加消费总额/积分
  248. $weizhi=strpos($order['money'],'.');
  249. if($weizhi){
  250. $money=substr($order['money'],'0',$weizhi);
  251. }else{
  252. $money=$order['money'];
  253. }
  254. $update_user=[
  255. 'cumulative_money'=>bcadd($order['money'],$user['cumulative_money'],2),
  256. ];
  257. // if($mer_id=='276'||$mer_id=='236'){
  258. // if($order['money']>=1){
  259. // if($user['first_consumption_one']==1){
  260. // if($type==2){
  261. //
  262. // $bill=[
  263. // 'from_id'=>'0',
  264. // 'number'=>100,
  265. // 'to_id'=>$user['eb_id'],
  266. // 'type'=>'1',
  267. // 'order_no'=>$order['order_no'],
  268. // 'remarks'=>'首次消费满1元赠送100积分',
  269. // 'pm'=>1,
  270. // 'status'=>2,
  271. // 'on_line'=>2,
  272. // 'mer_id'=>$mer_id
  273. // ];
  274. // $this->eb_user_bill($bill);
  275. // Db::name('entropy_barter_user_'.$mer_id)->where('eb_id',$user['eb_id'])->inc('integral',100)->update();
  276. // Db::name('entropy_barter_user_'.$mer_id)->where('eb_id',$user['eb_id'])->inc('first_consumption_one',1)->update();
  277. //
  278. // }else{
  279. //
  280. // $bill=[
  281. // 'from_id'=>'0',
  282. // 'number'=>100,
  283. // 'to_id'=>$user['eb_id'],
  284. // 'type'=>'1',
  285. // 'order_no'=>$order['order_no'],
  286. // 'remarks'=>'首次消费满1元赠送100积分',
  287. // 'pm'=>1,
  288. // 'status'=>1,
  289. // 'on_line'=>1,
  290. // 'mer_id'=>$mer_id
  291. // ];
  292. // $this->eb_user_bill($bill);
  293. // Db::name('entropy_barter_user_'.$mer_id)->where('eb_id',$user['eb_id'])->inc('first_consumption_one',1)->update();
  294. // }
  295. //
  296. // }
  297. // }
  298. // }
  299. if($user['type']==1){
  300. if($update_user['cumulative_money']>=6000){
  301. $update['integral']='6000';
  302. }
  303. }
  304. $reward_one=Db::name('entropy_barter_config_'.$mer_id)->where('key','reward_one')->find();
  305. if($update_user['cumulative_money']>=$reward_one||$mer_id=='236'){
  306. if($type==2){
  307. Db::name('entropy_barter_user_'.$mer_id)->where('eb_id',$user['eb_id'])->update($update_user);
  308. $bill=[
  309. 'from_id'=>'0',
  310. 'number'=>$money,
  311. 'to_id'=>$user['eb_id'],
  312. 'type'=>'1',
  313. 'order_no'=>$order['order_no'],
  314. 'remarks'=>'消费得积分',
  315. 'pm'=>1,
  316. 'status'=>2,
  317. 'on_line'=>2,
  318. 'mer_id'=>$mer_id
  319. ];
  320. $this->eb_user_bill($bill);
  321. }else{
  322. $bill=[
  323. 'from_id'=>'0',
  324. 'number'=>$money,
  325. 'to_id'=>$user['eb_id'],
  326. 'type'=>'1',
  327. 'order_no'=>$order['order_no'],
  328. 'remarks'=>'消费得积分',
  329. 'pm'=>1,
  330. 'status'=>1,
  331. 'on_line'=>1,
  332. 'mer_id'=>$mer_id
  333. ];
  334. $this->eb_user_bill($bill);
  335. }
  336. }
  337. $eb_user=Db::name('entropy_barter_user_'.$mer_id)->where('uid',$order['uid'])->find();
  338. $reward_two=Db::name('entropy_barter_config_'.$mer_id)->where('key','reward_two')->find();
  339. $reward_three=Db::name('entropy_barter_config_'.$mer_id)->where('key','reward_three')->find();
  340. $reward_four=Db::name('entropy_barter_config_'.$mer_id)->where('key','reward_four')->find();
  341. Db::name('log')->insert(['data'=>'这是我总共的消费'.$eb_user['cumulative_money']]);
  342. Db::name('log')->insert(['data'=>'1'.json_encode($reward_one)]);
  343. Db::name('log')->insert(['data'=>'2'.json_encode($reward_two)]);
  344. Db::name('log')->insert(['data'=>'3'.json_encode($reward_three)]);
  345. Db::name('log')->insert(['data'=>'4'.json_encode($reward_four)]);
  346. if($eb_user['cumulative_money']>=$reward_one['value'] and $eb_user['cumulative_money']<$reward_two['value']){
  347. $update['type']=2;
  348. $update_config['value']=$reward_one['id'];
  349. }elseif ($eb_user['cumulative_money']>=$reward_two['value'] and $eb_user['cumulative_money']<$reward_three['value']){
  350. $update['type']=3;
  351. $update_config['value']=$reward_two['id'];
  352. }elseif ($eb_user['cumulative_money']>=$reward_three['value'] and $eb_user['cumulative_money']<$reward_four['value']){
  353. $update['type']=4;
  354. $update_config['value']=$reward_three['id'];
  355. }elseif ($eb_user['cumulative_money']>=$reward_four['value']){
  356. $update['type']=5;
  357. $update_config['value']=$reward_four['id'];
  358. }
  359. //修改此用户佣金比例
  360. if($type==2){
  361. Db::name('entropy_barter_config_user_'.$mer_id)->where('eb_id',$user['eb_id'])->update($update_config);
  362. //修改此用户类型 2 会员 3经理 4 总监 5 总裁
  363. Db::name('entropy_barter_user_'.$mer_id)->where('eb_id',$user['eb_id'])->update($update);
  364. }
  365. //是否有上级
  366. if($user['top_eb_id']){
  367. $top_user=Db::name('entropy_barter_user_'.$mer_id)->where('eb_id',$user['top_eb_id'])->find();
  368. $wallet=bcmul($order['money'],bcmul(30,0.01,2),2);
  369. if($top_user['integral']>=$wallet){
  370. if($type==2){
  371. $bill=[
  372. 'from_id'=>'0',
  373. 'number'=>$wallet,
  374. 'to_id'=>$top_user['eb_id'],
  375. 'type'=>'2',
  376. 'order_no'=>$order['order_no'],
  377. 'remarks'=>'直推佣金',
  378. 'pm'=>1,
  379. 'status'=>2,
  380. 'on_line'=>2,
  381. 'mer_id'=>$mer_id
  382. ];
  383. $this->eb_user_bill($bill);
  384. Db::name('entropy_barter_user_'.$mer_id)->where('eb_id',$top_user['eb_id'])->inc('wallet',$wallet)->update();
  385. Db::name('entropy_barter_user_'.$mer_id)->where('eb_id',$top_user['eb_id'])->dec('integral',$wallet)->update();
  386. }else{
  387. $bill=[
  388. 'from_id'=>'0',
  389. 'number'=>$wallet,
  390. 'to_id'=>$top_user['eb_id'],
  391. 'type'=>'2',
  392. 'order_no'=>$order['order_no'],
  393. 'remarks'=>'直推佣金',
  394. 'pm'=>1,
  395. 'status'=>1,
  396. 'on_line'=>1,
  397. 'mer_id'=>$mer_id
  398. ];
  399. $this->eb_user_bill($bill);
  400. }
  401. }
  402. $top_level=Db::name('entropy_barter_user_'.$mer_id)->where('eb_id',$top_user['top_eb_id'])->find();
  403. if($top_level){
  404. $table_name='entropy_barter_config_'.$mer_id;
  405. $cproportion=Db::name('entropy_barter_config_user_'.$mer_id)
  406. ->alias('ebcu')
  407. ->leftJoin($table_name .' ebc','ebcu.value=ebc.id')
  408. ->where('eb_id',$top_level['eb_id'])
  409. ->field('ebc.proportion')
  410. ->find();
  411. $integral=bcmul($money,bcmul($cproportion['proportion'],'0.01',2),2);
  412. if($integral>0){
  413. if($type==2) {
  414. Db::name('entropy_barter_user_'.$mer_id)->where('eb_id',$top_level['eb_id'])->inc('integral',$integral)->update();
  415. $bill=[
  416. 'from_id'=>'0',
  417. 'number'=>$integral,
  418. 'to_id'=>$top_level['eb_id'],
  419. 'type'=>'2',
  420. 'order_no'=>$order['order_no'],
  421. 'remarks'=>'团队积分奖励',
  422. 'pm'=>1,
  423. 'status'=>2,
  424. 'on_line'=>2,
  425. 'mer_id'=>$mer_id
  426. ];
  427. $this->eb_user_bill($bill);
  428. }else{
  429. $bill=[
  430. 'from_id'=>'0',
  431. 'number'=>$integral,
  432. 'to_id'=>$top_level['eb_id'],
  433. 'type'=>'1',
  434. 'order_no'=>$order['order_no'],
  435. 'remarks'=>'团队积分奖励',
  436. 'pm'=>1,
  437. 'status'=>1,
  438. 'on_line'=>1,
  439. 'mer_id'=>$mer_id
  440. ];
  441. $this->eb_user_bill($bill);
  442. }
  443. }
  444. }
  445. }
  446. }
  447. //账单记录
  448. public function eb_user_bill($bill)
  449. {
  450. $insert=[
  451. 'from_id'=>$bill['from_id'],
  452. 'number'=>$bill['number'],
  453. 'to_id'=>$bill['to_id'],
  454. 'type'=>$bill['type'],
  455. 'order_no'=>$bill['order_no'],
  456. 'remarks'=>$bill['remarks'],
  457. 'pm'=>$bill['pm'],
  458. 'ctime'=>time(),
  459. 'on_line'=>$bill['on_line'],
  460. 'status'=>$bill['status'],
  461. 'pm2_msg'=>$bill['pm2_msg']??'',
  462. 'mer_id'=>$bill['mer_id'],
  463. 'commission_scale'=>$bill['commission_scale']??0,
  464. 'commission_type'=>$bill['commission_type']??0,
  465. 'to_user_type'=>$bill['to_user_type']??'',
  466. 'to_user_type_1'=>$bill['to_user_type_1']??'',
  467. ];
  468. Db::name('log')->insert(['data'=>json_encode($insert)]);
  469. Db::name('entropy_barter_bill')->insert($insert);
  470. }
  471. //积分赠送
  472. public function give_integral()
  473. {
  474. $mer_id=$this->request->params(['mer_id']);
  475. if(empty($mer_id['mer_id'])){
  476. return app('json')->fail('请联系技术人员排查问题,感谢您的反馈');
  477. }else{
  478. $mer_id=$mer_id['mer_id'];
  479. }
  480. $param=$this->request->param();
  481. $uid = $this->request->uid();
  482. $cxbuser_from=Db::name('user')->where('uid',$uid)->find();
  483. $cxbuser_to=Db::name('user')->where('uid',$param['to_id'])->find();
  484. $user=Db::name('entropy_barter_user_'.$mer_id)->where('uid',$uid)->find();
  485. $touser=Db::name('entropy_barter_user_'.$mer_id)->where('uid',$param['to_id'])->find();
  486. if(!$touser){
  487. return app('json')->fail('未查询到用户(赠送)');
  488. }
  489. $from_id=$user['eb_id'];
  490. $to_id=$touser['eb_id'];
  491. $number=$param['unmber'];
  492. if($user['integral']<$number){
  493. return app('json')->fail('积分不足,赠送失败。');
  494. }
  495. $update_from=[
  496. 'integral'=>$number
  497. ];
  498. Db::name('entropy_barter_user_'.$mer_id)->where('eb_id',$from_id)->update($update_from);
  499. $bill=[
  500. 'from_id'=>$from_id,
  501. 'number'=>$number,
  502. 'to_id'=>$to_id,
  503. 'type'=>'1',
  504. 'order_no'=>'0',
  505. 'remarks'=>'赠送给'.$cxbuser_to['nickname'].$number.'积分',
  506. 'pm'=>2,
  507. 'status'=>2,
  508. 'mer_id'=>$mer_id
  509. ];
  510. $this->eb_user_bill($bill);
  511. $update_to=[
  512. 'integral'=>$number
  513. ];
  514. Db::name('entropy_barter_user_'.$mer_id)->where('eb_id',$to_id)->update($update_to);
  515. $bill=[
  516. 'from_id'=>$from_id,
  517. 'number'=>$number,
  518. 'to_id'=>$to_id,
  519. 'type'=>'1',
  520. 'order_no'=>'0',
  521. 'remarks'=>$cxbuser_from['nickname'].'赠送给我'.$number.'积分',
  522. 'pm'=>1,
  523. 'status'=>2,
  524. 'mer_id'=>$mer_id
  525. ];
  526. $this->eb_user_bill($bill);
  527. return app('json')->success('赠送成功');
  528. }
  529. //搜索好友
  530. public function search_friends()
  531. {
  532. $phone=$this->request->params(['phone']);
  533. if(!empty($phone)){
  534. app('json')->fail('未接收到参数 phone');
  535. }
  536. $user_data=Db::name('user')->where('account',$phone)->field('uid')->find();
  537. if(!$user_data){
  538. app('json')->fail('未查询到用户--'.$phone);
  539. }
  540. return app('json')->success(['uid'=>$user_data['uid']]);
  541. }
  542. //个人中心
  543. public function personals()
  544. {
  545. $uid=$this->request->uid();
  546. $mer_id=$this->request->params(['mer_id']);
  547. if(empty($mer_id['mer_id'])){
  548. return app('json')->fail('请联系技术人员排查问题,感谢您的反馈');
  549. }else{
  550. $mer_id=$mer_id['mer_id'];
  551. }
  552. $userdata=Db::name('entropy_barter_user_'.$mer_id)
  553. ->alias('ebu')
  554. ->leftJoin('user u','u.uid=ebu.uid')
  555. ->where('ebu.uid',$uid)
  556. ->find();
  557. if (!$userdata){
  558. return app('json')->fail('还未注册');
  559. }
  560. $unsettled_integral=Db::name('entropy_barter_bill')
  561. ->where('mer_id',$mer_id)
  562. ->where('type',1)
  563. ->where('to_id',$userdata['eb_id'])
  564. ->where('pm',1)
  565. ->where('status',1)
  566. ->sum('number');
  567. $userdata['unsettled_integral']=$unsettled_integral;
  568. if($userdata['avatar']=='https://cdn.bjtdba.com/chuxubao/static/assets/yhc_default_avatar.png'){
  569. $userdata['avatar']=Db::name('user_account')->where('type',1)->where('uid',$uid)->value('avater');
  570. if(empty($userdata['avatar'])){
  571. $userdata['avatar']=Db::name('user_account')->where('type',2)->where('uid',$uid)->value('avater');
  572. if(empty($userdata['avatar'])){
  573. $userdata['avatar']='https://cdn.bjtdba.com/chuxubao/static/assets/yhc_default_avatar.png';
  574. }
  575. }
  576. }
  577. if($mer_id==290){
  578. $userdata['url']=$this->zhongjiankangyang_pic($userdata);
  579. }
  580. if ($userdata)
  581. return app('json')->success($userdata);
  582. else
  583. return app('json')->fail('暂无数据');
  584. }
  585. public function zhongjiankangyang_pic($user)
  586. {
  587. if($user['type']!=0){
  588. if($user['pay_goods_type']==1){
  589. switch ($user['type']){
  590. case 3:
  591. $url='https://app.bjtdba.com/applet/static/images/zjky/type3pay_goods_type1.png';
  592. break;
  593. case 4:
  594. $url='https://app.bjtdba.com/applet/static/images/zjky/type4pay_goods_type1.png';
  595. break;
  596. case 5:
  597. $url='https://app.bjtdba.com/applet/static/images/zjky/type5pay_goods_type1.png';
  598. break;
  599. case 6:
  600. $url='https://app.bjtdba.com/applet/static/images/zjky/type6pay_goods_type1.png';
  601. break;
  602. case 7:
  603. $url='https://app.bjtdba.com/applet/static/images/zjky/heijin.png';
  604. break;
  605. case 1:
  606. default:
  607. $url='https://app.bjtdba.com/applet/static/images/zjky/type1pay_goods_type1.png';
  608. }
  609. }elseif($user['pay_goods_type']==2){
  610. switch ($user['type']){
  611. case 3:
  612. $url='https://app.bjtdba.com/applet/static/images/zjky/type3pay_goods_type2.png';
  613. break;
  614. case 4:
  615. $url='https://app.bjtdba.com/applet/static/images/zjky/type4pay_goods_type2.png';
  616. break;
  617. case 5:
  618. $url='https://app.bjtdba.com/applet/static/images/zjky/type5pay_goods_type2.png';
  619. break;
  620. case 6:
  621. $url='https://app.bjtdba.com/applet/static/images/zjky/type6pay_goods_type2.png';
  622. break;
  623. case 7:
  624. $url='https://app.bjtdba.com/applet/static/images/zjky/heijin.png';
  625. break;
  626. case 2:
  627. default:
  628. $url='https://app.bjtdba.com/applet/static/images/zjky/type2pay_goods_type2.png';
  629. }
  630. }
  631. }else{
  632. $url=1;
  633. }
  634. return $url;
  635. }
  636. //下级用户
  637. public function subordinate()
  638. {
  639. [$page,$limit] = $this->getPage();
  640. $uid=$this->request->uid();
  641. $type=$this->request->params(['type']);
  642. if(empty($type['type'])){
  643. return app('json')->fail('未获取到参数: type');
  644. }
  645. $mer_id=$this->request->params(['mer_id']);
  646. if(empty($mer_id['mer_id'])){
  647. return app('json')->fail('请联系技术人员排查问题,感谢您的反馈');
  648. }else{
  649. $mer_id=$mer_id['mer_id'];
  650. }
  651. $type=$type['type'];
  652. if($type==1){
  653. // $user_data=Db::name('entropy_barter_user_'.$mer_id)->where('uid',$uid)->field('nickname,account,create_time,')->select();
  654. $ebuser=Db::name('entropy_barter_user_'.$mer_id)->where('uid',$uid)->find();
  655. $user_data=Db::name('entropy_barter_user_'.$mer_id)->where('top_eb_id',$ebuser['eb_id'])->page($page,$limit)->select();
  656. $num=Db::name('entropy_barter_user_'.$mer_id)->where('top_eb_id',$ebuser['eb_id'])->count('eb_id');
  657. if($user_data->isEmpty()){
  658. return app('json')->success([]);
  659. }
  660. $user_data=$user_data->toArray();
  661. foreach ($user_data as $k=>&$v){
  662. $cxb_user=Db::name('user')->where('uid',$v['uid'])->field('nickname,avatar,create_time')->find();
  663. $v['avatar']=$cxb_user['avatar'];
  664. if($cxb_user['avatar']=='https://cdn.bjtdba.com/chuxubao/static/assets/yhc_default_avatar.png'){
  665. $v['avatar']=Db::name('user_account')->where('type',1)->where('uid',$v['uid'])->value('avater');
  666. if(empty($v['avatar'])){
  667. $v['avatar']=Db::name('user_account')->where('type',2)->where('uid',$v['uid'])->value('avater');
  668. if(empty($v['avatar'])){
  669. $v['avatar']='https://cdn.bjtdba.com/chuxubao/static/assets/yhc_default_avatar.png';
  670. }
  671. }
  672. }
  673. $v['nickname']=$cxb_user['nickname'];
  674. $v['create_time']=date('Y-m-d H:i:s',$v['ctime']);
  675. $v['money']=Db::name('store_order')->where('mer_id',$mer_id)->where('uid',$v['uid'])->where('paid',1)->where('status','<>','-1')->sum('total_price');
  676. $v['order']=Db::name('store_order')->where('mer_id',$mer_id)->where('uid',$v['uid'])->where('paid',1)->where('status','<>','-1')->count('order_id');
  677. $v['extension']=Db::name('entropy_barter_user_'.$mer_id)->where('top_eb_id',$v['eb_id'])->count('eb_id');
  678. }
  679. }elseif($type==2){
  680. $ebuser=Db::name('entropy_barter_user_'.$mer_id)->where('uid',$uid)->find();
  681. $top_user=Db::name('entropy_barter_user_'.$mer_id)->where('top_eb_id',$ebuser['eb_id'])->select();
  682. if($top_user->isEmpty()){
  683. return app('json')->success([]);
  684. }
  685. $top_user=$top_user->toArray();
  686. $ids='';
  687. foreach ($top_user as $k=>$v){
  688. $ids.=$v['eb_id'].',';
  689. }
  690. $ids=explode(',',rtrim($ids,','));
  691. $user_data=Db::name('entropy_barter_user_'.$mer_id)->whereIn('top_eb_id',$ids)->page($page,$limit)->select();
  692. $num=Db::name('entropy_barter_user_'.$mer_id)->whereIn('top_eb_id',$ids)->count('eb_id');
  693. if($user_data->isEmpty()){
  694. return app('json')->success([]);
  695. }
  696. $user_data=$user_data->toArray();
  697. foreach ($user_data as $k=>&$v){
  698. $cxb_user=Db::name('user')->where('uid',$v['uid'])->field('nickname,avatar,create_time')->find();
  699. // dd($cxb_user);
  700. $v['avatar']=$cxb_user['avatar'];
  701. if($cxb_user['avatar']=='https://cdn.bjtdba.com/chuxubao/static/assets/yhc_default_avatar.png'){
  702. $v['avatar']=Db::name('user_account')->where('type',1)->where('uid',$v['uid'])->value('avater');
  703. if(empty($v['avatar'])){
  704. $v['avatar']=Db::name('user_account')->where('type',2)->where('uid',$v['uid'])->value('avater');
  705. if(empty($v['avatar'])){
  706. $v['avatar']='https://cdn.bjtdba.com/chuxubao/static/assets/yhc_default_avatar.png';
  707. }
  708. }
  709. }
  710. $v['nickname']=$cxb_user['nickname'];
  711. $v['create_time']=date('Y-m-d H:i:s',$v['ctime']);
  712. $v['money']=Db::name('store_order')->where('mer_id',$mer_id)->where('paid',1)->where('uid',$v['uid'])->sum('total_price');
  713. $v['order']=Db::name('store_order')->where('mer_id',$mer_id)->where('paid',1)->where('uid',$v['uid'])->count('order_id');
  714. }
  715. }else{
  716. $user_data=[];
  717. }
  718. return app('json')->success(compact('user_data','num'));
  719. }
  720. //确认收货
  721. public function take($order_no)
  722. {
  723. Db::name('log')->insert(['data'=>'易熵易物我走进来了']);
  724. try {
  725. $mer_id=Db::name('store_order')->where('order_sn',$order_no)->value('mer_id');
  726. if($mer_id=='290'){
  727. $this->take_290($order_no);
  728. }
  729. $data=Db::name('entropy_barter_bill')->where('mer_id',$mer_id)->where('order_no',$order_no)->select();
  730. $order_data=Db::name('store_order')->where('order_sn',$order_no)->find();
  731. if($order_data['pay_price']>=1){
  732. $true=true;
  733. }else{
  734. $true=false;
  735. }
  736. Db::name('log')->insert(['data'=>'数据---'.json_encode($data)]);
  737. if($data->isEmpty()){
  738. return '12';
  739. }
  740. $data=$data->toArray();
  741. foreach ($data as $k=>$v){
  742. // if($true){
  743. // Db::name('entropy_barter_user_'.$mer_id)->where('eb_id',$v['to_id'])->inc('integral',100)->update();
  744. // }
  745. $true=false;
  746. if($v['status']=='1'){
  747. if($v['type']==2){
  748. Db::name('entropy_barter_user_'.$mer_id)->where('eb_id',$v['to_id'])->inc('wallet',$v['number'])->update();
  749. Db::name('entropy_barter_user_'.$mer_id)->where('eb_id',$v['to_id'])->dec('integral',$v['number'])->update();
  750. Db::name('entropy_barter_bill')->where('id',$v['id'])->update(['status'=>2]);
  751. }elseif ($v['type']==1){
  752. Db::name('entropy_barter_user_'.$mer_id)->where('eb_id',$v['to_id'])->inc('integral',$v['number'])->update();
  753. Db::name('entropy_barter_bill')->where('id',$v['id'])->update(['status'=>2]);
  754. }
  755. }
  756. }
  757. $uid=Db::name('store_order')->where('order_sn',$order_no)->value('uid');
  758. $eb_user=Db::name('entropy_barter_user_'.$mer_id)->where('uid',$uid)->find();
  759. $reward_one=Db::name('entropy_barter_config_'.$mer_id)->where('key','reward_one')->find();
  760. $reward_two=Db::name('entropy_barter_config_'.$mer_id)->where('key','reward_two')->find();
  761. $reward_three=Db::name('entropy_barter_config_'.$mer_id)->where('key','reward_three')->find();
  762. $reward_four=Db::name('entropy_barter_config_'.$mer_id)->where('key','reward_four')->find();
  763. Db::name('log')->insert(['data'=>'这是我总共的消费'.$eb_user['cumulative_money']]);
  764. Db::name('log')->insert(['data'=>'1'.json_encode($reward_one)]);
  765. Db::name('log')->insert(['data'=>'2'.json_encode($reward_two)]);
  766. Db::name('log')->insert(['data'=>'3'.json_encode($reward_three)]);
  767. Db::name('log')->insert(['data'=>'4'.json_encode($reward_four)]);
  768. $update_config=[];
  769. $update=[];
  770. if($eb_user['cumulative_money']>=$reward_one['value'] and $eb_user['cumulative_money']<$reward_two['value']){
  771. $update['type']=2;
  772. $update_config['value']=$reward_one['id'];
  773. }elseif ($eb_user['cumulative_money']>=$reward_two['value'] and $eb_user['cumulative_money']<$reward_three['value']){
  774. $update['type']=3;
  775. $update_config['value']=$reward_two['id'];
  776. }elseif ($eb_user['cumulative_money']>=$reward_three['value'] and $eb_user['cumulative_money']<$reward_four['value']){
  777. $update['type']=4;
  778. $update_config['value']=$reward_three['id'];
  779. }elseif ($eb_user['cumulative_money']>=$reward_four['value']){
  780. $update['type']=5;
  781. $update_config['value']=$reward_four['id'];
  782. }
  783. Db::name('entropy_barter_user_'.$mer_id)->where('eb_id',$eb_user['eb_id'])->update(['cumulative_money'=>bcadd($eb_user['cumulative_money'],$order_data['pay_price'],2)]);
  784. //修改此用户佣金比例
  785. Db::name('entropy_barter_config_user_'.$mer_id)->where('eb_id',$eb_user['eb_id'])->update($update_config);
  786. //修改此用户类型 2 会员 3经理 4 总监 5 总裁
  787. Db::name('entropy_barter_user_'.$mer_id)->where('eb_id',$eb_user['eb_id'])->update($update);
  788. }catch (Exception $exception){
  789. Db::name("log")->insert(array('data'=>$exception->getFile().':'.$exception->getLine().'【'.$exception->getMessage().'】'));//日志记录
  790. }
  791. }
  792. //退款
  793. public function refund($order_no)
  794. {
  795. try {
  796. $mer_id=Db::name('store_order')->where('order_sn',$order_no)->value('mer_id');
  797. $data=Db::name('entropy_barter_bill')->where('mer_id',$mer_id)->where('order_no',$order_no)->select();
  798. if($data->isEmpty()){
  799. return "123123131";
  800. }
  801. $data=$data->toArray();
  802. foreach ($data as $k=>$v){
  803. Db::name('entropy_barter_bill')->where('id',$v['id'])->update(['status'=>3]);
  804. if($v['status']=='2'){
  805. if($v['type']==2){
  806. Db::name('entropy_barter_user_'.$mer_id)->where('eb_id',$v['to_id'])->dec('wallet',$v['number'])->update();
  807. Db::name('entropy_barter_user_'.$mer_id)->where('eb_id',$v['to_id'])->inc('integral',$v['number'])->update();
  808. }elseif ($v['type']==1){
  809. Db::name('entropy_barter_user_'.$mer_id)->where('eb_id',$v['to_id'])->dec('integral',$v['number'])->update();
  810. }
  811. }
  812. }
  813. $uid=Db::name('store_order')->where('order_sn',$order_no)->value('uid');
  814. $eb_user=Db::name('entropy_barter_user_'.$mer_id)->where('uid',$uid)->find();
  815. $reward_one=Db::name('entropy_barter_config_'.$mer_id)->where('key','reward_one')->find();
  816. $reward_two=Db::name('entropy_barter_config_'.$mer_id)->where('key','reward_two')->find();
  817. $reward_three=Db::name('entropy_barter_config_'.$mer_id)->where('key','reward_three')->find();
  818. $reward_four=Db::name('entropy_barter_config_'.$mer_id)->where('key','reward_four')->find();
  819. Db::name('log')->insert(['data'=>'2'.json_encode($reward_one)]);
  820. Db::name('log')->insert(['data'=>'2'.json_encode($reward_two)]);
  821. Db::name('log')->insert(['data'=>'3'.json_encode($reward_three)]);
  822. Db::name('log')->insert(['data'=>'4'.json_encode($reward_four)]);
  823. $update_config=[];
  824. $update=[];
  825. if($eb_user['cumulative_money']>=$reward_one['value'] and $eb_user['cumulative_money']<$reward_two['value']){
  826. $update['type']=2;
  827. $update_config['value']=$reward_one['id'];
  828. }elseif ($eb_user['cumulative_money']>=$reward_two['value'] and $eb_user['cumulative_money']<$reward_three['value']){
  829. $update['type']=3;
  830. $update_config['value']=$reward_two['id'];
  831. }elseif ($eb_user['cumulative_money']>=$reward_three['value'] and $eb_user['cumulative_money']<$reward_four['value']){
  832. $update['type']=4;
  833. $update_config['value']=$reward_three['id'];
  834. }elseif ($eb_user['cumulative_money']>=$reward_four['value']){
  835. $update['type']=5;
  836. $update_config['value']=$reward_four['id'];
  837. }else{
  838. $update['type']=1;
  839. $update_config['value']=0;
  840. }
  841. //修改此用户佣金比例
  842. Db::name('entropy_barter_config_user')->where('eb_id',$eb_user['eb_id'])->update($update_config);
  843. //修改此用户类型 2 会员 3经理 4 总监 5 总裁
  844. Db::name('entropy_barter_user_'.$mer_id)->where('eb_id',$eb_user['eb_id'])->update($update);
  845. }catch (Exception $exception){
  846. Db::name("log")->insert(array('data'=>$exception->getFile().':'.$exception->getLine().'【'.$exception->getMessage().'】'));//日志记录
  847. }
  848. }
  849. /**
  850. * 我的订单
  851. */
  852. public function my_order()
  853. {
  854. $mer_id=$this->request->params(['mer_id']);
  855. if(empty($mer_id['mer_id'])){
  856. return app('json')->fail('请联系技术人员排查问题,感谢您的反馈');
  857. }else{
  858. $mer_id=$mer_id['mer_id'];
  859. }
  860. [$page,$limit] = $this->getPage();
  861. $uid=$this->request->uid();
  862. $status=$this->request->params(['status']);
  863. // //订单状态(0:待发货;1:待收货;3:已完成;4售后 -2 待支付)
  864. // $page=1;
  865. // $limit=10;
  866. // $status['status']='1';
  867. // $uid=1824;
  868. $where=$status;
  869. if(empty($where['status'])){
  870. $where=[];
  871. }elseif ($where['status']==999){
  872. $where=[];
  873. }
  874. if($status['status']==4|| $status['status']=='-1'){
  875. // $data=Db::name('store_refund_order')->where('uid',$uid)->where('mer_id',276)->page($page,$limit)->select();
  876. $data=Db::name('store_order')->order('create_time','desc')->where('status','in','-1,4')->where('uid',$uid)->where('mer_id',$mer_id)->page($page,$limit)->select();
  877. if($data->isEmpty()){
  878. return app('json')->success([]);
  879. }
  880. }elseif($status['status']=='-2'){
  881. $data=Db::name('store_order')->order('create_time','desc')->where('uid',$uid)->where('is_del','0')->where('paid',0)->where('mer_id',$mer_id)->page($page,$limit)->select();
  882. }elseif ($status['status']==3){
  883. $data=Db::name('store_order')->order('create_time','desc')->where('uid',$uid)->where('is_del','0')->where('mer_id',$mer_id)->where('status',3)->page($page,$limit)->select();
  884. }elseif($status['status']==0){
  885. $data=Db::name('store_order')->order('create_time','desc')->where('uid',$uid)->where('is_del','0')->where('mer_id',$mer_id)->where('status',0)->page($page,$limit)->select();
  886. }else{
  887. $data=Db::name('store_order')->order('create_time','desc')->where($where)->where('is_del','0')->where('uid',$uid)->where('paid',1)->where('mer_id',$mer_id)->page($page,$limit)->select();
  888. }
  889. if($data->isEmpty()){
  890. return app('json')->success([]);
  891. }
  892. $data=$data->toArray();
  893. foreach ($data as $k=>&$v){
  894. $goods_data=Db::name('store_order_product')
  895. ->alias('sop')
  896. ->leftJoin('store_product sp','sop.product_id=sp.product_id')
  897. ->where('order_id',$v['order_id'])
  898. ->field('sp.image,sp.store_name,sop.product_num,sop.product_price,sop.product_id')
  899. ->find();
  900. $v['product']=$goods_data;
  901. $v['orderProduct']=Db::name('store_order_product')->where('order_id',$v['order_id'])->select();
  902. }
  903. return app('json')->success($data);
  904. }
  905. //提现
  906. public function withdrawal()
  907. {
  908. $param=$this->request->param();
  909. $money=$param['money'];
  910. $uid=$this->request->uid();
  911. $extract_type=$param['extract_type'];
  912. $mer_id=$this->request->params(['mer_id']);
  913. if(empty($mer_id['mer_id'])){
  914. return app('json')->fail('请联系技术人员排查问题,感谢您的反馈');
  915. }else{
  916. $mer_id=$mer_id['mer_id'];
  917. }
  918. $userData = Db::name('user') -> where('uid',$uid) -> find();
  919. if($extract_type==2){
  920. if($userData['ali_user_id'] == '0' || $userData['ali_user_id'] == ''){
  921. return app('json')->success('未绑定支付宝账户');
  922. }
  923. }
  924. // $user=Db::name('user')->where('uid',$uid)->find();
  925. $eb_id=Db::name('entropy_barter_user_'.$mer_id)->where('uid',$uid)->find();
  926. if(empty($eb_id)){
  927. return app('json')->success('未查询到用户信息');
  928. }
  929. if(bcsub($eb_id['wallet'],$money,2)<'0'){
  930. return app('json')->fail('提现失败,佣金不够');
  931. }
  932. // if($money>'200'){
  933. // return app('json')->fail('一次最高提现200');
  934. // }
  935. if (!$userData){
  936. return app('json')->fail('用户信息错误');
  937. }
  938. if($extract_type==2){
  939. $order_sn='Ali'.time().rand('111111111','999999999');
  940. }elseif ($extract_type==1){
  941. $order_sn='wx'.time().rand('111111111','999999999');
  942. }
  943. $service_money=bcmul($money,'0.06',2);
  944. // $money=bcsub($money,$service_money,2);
  945. $insert_data=[
  946. 'uid'=>$uid,
  947. 'real_name'=>$userData['nickname'],
  948. 'extract_type'=>$extract_type,
  949. 'extract_price'=>$money,
  950. 'type'=>1,
  951. 'order_sn'=>$order_sn,
  952. 'status'=>0,
  953. 'withdrawal_type'=>2,
  954. 'mer_id'=>$mer_id,
  955. 'service_money'=>$service_money
  956. ];
  957. if($extract_type==2){
  958. $insert_data['alipay_code']=$userData['account'];
  959. }elseif ($extract_type==1){
  960. $insert_data['wechat']=$userData['account'];
  961. }
  962. Db::name('user_extract')->insert($insert_data);
  963. $bill=[
  964. 'from_id'=>'0',
  965. 'number'=>$money,
  966. 'to_id'=>$eb_id['eb_id'],
  967. 'type'=>'2',
  968. 'order_no'=>$order_sn,
  969. 'remarks'=>'提现待审核',
  970. 'pm'=>2,
  971. 'status'=>1,
  972. 'pm2_msg'=>'提现',
  973. 'on_line'=>1,
  974. 'mer_id'=>$mer_id
  975. ];
  976. $this->eb_user_bill($bill);
  977. Db::name('entropy_barter_user_'.$mer_id)->where('uid',$uid)->dec('wallet',$money)->update();
  978. return app('json')->success('提交成功等待审核');
  979. }
  980. //团队订单
  981. public function order_lst()
  982. {
  983. $mer_id=$this->request->params(['mer_id']);
  984. if(empty($mer_id['mer_id'])){
  985. return app('json')->fail('请联系技术人员排查问题,感谢您的反馈');
  986. }else{
  987. $mer_id=$mer_id['mer_id'];
  988. }
  989. [$page,$limit] = $this->getPage();
  990. $uid=$this->request->uid();
  991. $click_id=$this->request->params(['click_id']);
  992. $type = $this -> request -> params(['type']);//默认线上订单
  993. if(empty($click_id) || $click_id['click_id']=='0'){
  994. return app('json')->fail('未查询到用户');
  995. }else{
  996. $click_id=$click_id['click_id'];
  997. }
  998. if($type['type'] == 1){
  999. $data=Db::name('store_order')->where('uid',$click_id)->page($page,$limit)->order('order_id','desc')->where('mer_id',$mer_id)->where('paid',1)->where('status','<>','-1')->field('order_id,uid,order_sn,create_time,total_price')->select();
  1000. }elseif ($type['type']==2){
  1001. $data = Db::name('order_merchant') -> where('uid',$click_id) ->page($page,$limit)->order('id','desc')->where('mer_id',$mer_id)->where('paid',1)->field('id as order_id,uid,out_trade_no as order_sn,create_time,money as total_price') ->select();
  1002. }
  1003. if($data->isEmpty()){
  1004. return app('json')->success([]);
  1005. }
  1006. $data=$data->toArray();
  1007. $eb_id=Db::name('entropy_barter_user_'.$mer_id)->where('uid',$uid)->find();
  1008. foreach ($data as $k=>&$v){
  1009. if($type['type']==1){
  1010. $bill=Db::name('entropy_barter_bill')->where('mer_id',$mer_id)->where('order_no',$v['order_sn'])->where('on_line',1)->where('to_id',$eb_id['eb_id'])->find();
  1011. }else{
  1012. $bill=Db::name('entropy_barter_bill')->where('mer_id',$mer_id)->where('order_no',$v['order_sn'])->where('on_line',2)->where('to_id',$eb_id['eb_id'])->find();
  1013. }
  1014. if($bill['type']==1){
  1015. $v['msg']='团队奖励'.$bill['number'].'积分';
  1016. }elseif ($bill['type']==2){
  1017. $v['msg']='直推奖励'.$bill['number'].'佣金';
  1018. }
  1019. if($bill['status']==1){
  1020. $v['status']='待确定';
  1021. }elseif ($bill['status']==2){
  1022. $v['status']='有效';
  1023. }elseif ($bill['status']==3){
  1024. $v['status']='已失效';
  1025. }
  1026. }
  1027. return app('json')->success($data);
  1028. }
  1029. /**
  1030. * 单笔转账接口
  1031. */
  1032. public function transfer()
  1033. {
  1034. $app_cert_path=dirname(__FILE__). '/../../../../extend/alipay/aop/cert/appCertPublicKey.crt';
  1035. $alipay_cert_path=dirname(__FILE__). '/../../../../extend/alipay/aop/cert/alipayCertPublicKey.crt';
  1036. $alipay_root_cert_path=dirname(__FILE__). '/../../../../extend/alipay/aop/cert/alipayRootCert.crt';
  1037. $url = "https://openapi.alipay.com/gateway.do";
  1038. $app_id="2021002194632049";
  1039. $privateKey="MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDGxceDFVT6VTYClinyAdY4PxE6MadNYLZ3sbLOLV14e39kuu1lkKDBZ/KPRNruPlSPGdiRVe+L8v4rsVk6bthsS/vMk5aH1wQyt58/HvHmZ5QVo3U5UD7cgqqefTcRJjKhjjM1rU/OrOkOqyssaLRukW3jeKRlBccUgtaGsXXrbMxWYpzl1OMDhKRRUVxu3LTfqlMpHghOasQrgyD92q9wlUN7U6hBYzGUocO/N3sz97PZwptwWAW0r3CFdlLCpgnMr+xb/Zh8td1OKGl3wEghiGavgDDlc2+w/xtk1SZ3pJbnGAU+D+oyJ6r76po6vkyGIlLrKp/zQ50az7fObzgNAgMBAAECggEBAK60szERlMkaEAih92gQGTsCo5+keMnX0UjO1LvGv7rfwQ7GBVYZklGrjVRDTrHL8wJ70w+amptFDgVVMXncZzh4aG5c4heu8q+pGLyf9DlwnIWQT736O+YQqun2YGogSqwYkgYBuH2NGKKd66pytPPhutYN+WAZfesXPHrSizRJtZMfuZvvGzm6ZJLZ1LmhvkOuLrX4xrJGRs1nAwZOmOfi4MY5VASblfPj59fUim9hErocNaX4uiMVwmhQl2QuOM/EbTd1UkW+dkV/gyQMOFzpcfN+SEi+hdLN+JiR9TVEcwity6ihOG5+3X33GKzfY4WFxeHHUaqA0SQWSkKofMECgYEA5OF5Imtq8/6JjWJ0jvYCpUnj9742McGJZTWBoTn9Hp0d3bwyE3YbH8pBVJyvzlfPKB9TUjE2FzVZvQtxEu+ZxToccp/LPqlgITWNHCmEtzAgXW7ww2PafgDZJ2QRSyjLUeRIWSAkeilj64XMCEC/bEs/nb5nmUb2gnsNTvvpMLUCgYEA3lMMtaIZH1fMI4XMNaPFzeRiKc0FIcLEem/efnPetPuOCujIWQJ/x9cCDCcfqO59I1FXQuiC/E1dFvme2qs/H7h2bFu8RG0M/ZQWd9twg31Sh+R7gCQakFERag8HXc4AWfBGXCvMu1SmSovU49KecSLxYGOAUdp77j1GxtLiePkCgYAQjc45ExPVOd+w/iH4BQsD8Wgvju5Ugu7xBwGtK4iHIk36r5XfmnczwWkgOYTto6Qz/rAEDdMfspge+CjhebrhbOaJ08zbZ1ywijL+inIy3aQ5ncCEIUC4RE9wbehiSz0JWz1wVMbOnxe+/RpYrnYp2vdq7U6I430IyuWXhNjE0QKBgEtJUmd7oghEIgPxfiq37/b+HOPM4q0BGKnhkjW+JS+idAJru9SwjPbub2oQIZ+CS2wXUnZ86EZqKFjsZQflr7WdMLUXB5UgXKLOcCFcdSiB2t3b2JqXH0u5uCzzM+pnJSVPwXPa/TR+wOVDnu8bVr43OAgNCdouI4OUyo/vv/N5AoGATJaIvpsZ9v1zmhbtJbgPBM9dhD2PIp2ufZ7yvhGGzA02FqAbyAeVsI2d+W+uA6jJ1X87x27pQv//mFoFXStxX3/bhdgTWbUYEWobAhw1jBS1rMQfLuBGGI/LsHGhzau3U+59erC5sYhGgZKSdXDyjOduWQlPWAv6ufkNZ+I3FCU=";
  1040. // 证书模式的测试
  1041. $alipayConfig = new AlipayConfig();
  1042. $alipayConfig->setAppId($app_id);
  1043. $alipayConfig->setCharset("utf-8");
  1044. $alipayConfig->setFormat("json");
  1045. $alipayConfig->setSignType("RSA2");
  1046. $alipayConfig->setServerUrl($url);
  1047. $alipayConfig->setPrivateKey($privateKey);
  1048. // content 和 path 只需要设置一个即可
  1049. $alipayConfig->setAppCertPath($app_cert_path);
  1050. //$alipayConfig->setAppCertContent()
  1051. $alipayConfig->setAlipayPublicCertPath($alipay_cert_path);
  1052. //$alipayConfig->setAlipayPublicCertContent()
  1053. $alipayConfig->setRootCertPath($alipay_root_cert_path);
  1054. //$alipayConfig->setRootCertContent()
  1055. $aop = new AopCertClient($alipayConfig);
  1056. $aop->isCheckAlipayPublicCert = true;
  1057. $parameter = "{".
  1058. "\"out_biz_no\":\"".rand(11111111,99999999)."\",".
  1059. "\"remark\":\"测试\",".
  1060. // "\"business_params\"":.json_encode(['payer_show_name_use_alias'=>'北京天地博爱网络科技有限公司']).
  1061. "\"business_params\":\"{'payer_show_name_use_alias':'北京天地博爱网络科技有限公司'}\",".
  1062. "\"biz_scene\":\"DIRECT_TRANSFER\",".
  1063. "\"payee_info\":{".
  1064. "\"identity\":\"3089507753@qq.com\",".
  1065. "\"identity_type\":\"ALIPAY_LOGON_ID\",".
  1066. "\"name\":\"唐世伟\"".
  1067. "},".
  1068. "\"trans_amount\":\"0.10\",".
  1069. "\"product_code\":\"TRANS_ACCOUNT_NO_PWD\",".
  1070. "\"order_title\":\"提现测试\"".
  1071. "}";
  1072. Db::name('log')->insert(['data'=>$parameter]);
  1073. $request = new AlipayFundTransUniTransferRequest ();
  1074. $request->setBizContent($parameter);
  1075. $response = $aop->execute($request);
  1076. Db::name('log')->insert(['data'=>'【返回结果】'.$response]);
  1077. $response=json_decode($response,true);
  1078. if($response['alipay_fund_trans_uni_transfer_response']['code']=='10000'){
  1079. return app('json')->success('提现成功');
  1080. }else{
  1081. return app('json')->fail($response['alipay_fund_trans_uni_transfer_response']['sub_msg']);
  1082. }
  1083. // $this->aop = new AopClient ();
  1084. // //配置参数
  1085. // $this->aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
  1086. // $this->aop->appId = '2021002194632049';
  1087. // $this->aop->rsaPrivateKey = 'MIIEpAIBAAKCAQEArqx2duK0hD6gC4vxHsblNi8zFI+bObJmMpSdeFpgK8TDNe9BHGR/YZmNzWKLGQMNgVXEplEAsA6slQkXxzNstRobbsr+TRxdbE3PDo3+WnfzvNcs7IwW+fjY53W81BXttpuvVIcNqXVREUC4gfyUufq1J042tpr5HtzggJKuDLn3q80HtXNaLYqZxGYQrTLaabvh4mco1YWCbYOsPd1b6jKRA9TqaeQilC9cOHcleMNQGjet4p4eqEIGnhjEudslMM/heYtKFP4h38KTWmZfgMFPZPnDuGAgNvOOOpp6sG9waRkRSkOkakGPgxUlIUazSHAHUuO1iAltg+F5cA/OowIDAQABAoIBAQCDNrza+9xdB2pUojBkTUb8GCLIDESv5+rLjkZolYNu/aUjC/KecIQb/iy+n4scI+XuRU6vHWRl3PAaGLWLB39e4BjBdq3noSow5JZpOZNbxIYNUprFq0rLRvsxjIlnzH1A0ty3o6hIpv9Z9YNk6ieTOdkBiMijDfGcFJJ1IzqqBX9fOvvgWS/lDOrmVV2JN4W9AHJVvc/f4geKoRJICnG8vsHX6rxvRwQh5Rvmg4aqVsj8JGKT+CmA9p2S7TZlFFi43IKPk/2ij1Kubu8rMf52kTlonFmtjbakP5WK8KOQOcU616uj9E3QMiTaHn1+mVZYW5ZDRwywYTK9y9Xh08GZAoGBANcHXR1Te7rgvnclM+RB5n1ud90TcptufOVeCAPvx9Co6yuAV1U1EduOZ5opWVNPGN4uSX87/1/RP7WVMdQAJqGG3HOINL+HsJLX32y2wdppCefL+d8sbHVuYXeQHeu/zaprAXW8CuBtxGIJadz+mQwMsoupMhx24+f6gaVz53ltAoGBAM/0qm4p9+mF8N+ScxCPUXbxN+gCjcrc0Zx1hNtOSH6WPRz1xx56/M5PkRN/cbNpKmIugPahMqgEO4zE7zDm6O0HpztmBHa0vA6Tu3TV9kPpyWLl0fBnM5mNC5zxNI062XUj4DG2RbGktAWDGEfNXPsq8dFNTdzQsts4yuGy9u5PAoGAE9+JWpGBqPbmg4p7rkfs7oDMMTF/8R+YCXbUVNDPbdh+y6lz6NsbyGfz6UqTB+ESkk5C2rCH3KoxMi4UydwttdYJ/9+ByIXY6ulqq9iEOBRnJvYyJM8tQvktpug567TxZCO5odD8TFu4v7rQ/uzE5lkyEzhS+lB+pc0AOHNq3E0CgYA2UtOys4PvnO2vebJVQRsm1xyjnwcrV0Pqe0iZgXmul9CfIBVEARzJSD+9uC0bkP1haISH6NQyz+g+fbN+MtPmF3m4Ko4/9DasGCt/+eS7GPdivmZ5RnxUQGQoO1pfCmCEGTsXwWWzYjMkvXo6R4tikXVaF7efV2VhnxRgoT+gQQKBgQCknz2HhZryDYiAwi88WueQjDUumr2F1Iywjt8nYOhI3ryuO/kiqAI8E/hPbdpvo0L52fdqgeyAOkp7ubQ0pNOgfZv8SQmN3JIfGqcgaLgskg5rRQyQywGgsdCUpJEGklK0uJP6vXjVBn/WceHMXDRusuwLhHa+Aq3yF6Z3hRSpKw==';//私钥
  1088. // $this->aop->alipayrsaPublicKey='MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuUb+0sJSNXjWiG0VJIPzn55+18af/fubYMpRLlreu34ewMgLx1zpCNpB3wrA+dylfWPMAm8PzvKnakByB+VJ/LMNhWHmF8Qkdo4astAikjlI4TMQCK/G384NzrtjHR4DGCDM5CMVt1xw5noF7kNBMYIvgDfhMCYmygdlIjuVdIlVEoQKOsT0RaNMleES0aZvbjvBGkGM0dsetqUExSjid9BF1NAO2ET+J3XMxCtMgCUVmFUvxsCKe6Rapa1/Lk3rzIeG6CRpoabuYfPM9E+3y3f3luSOMXLfH9lOSW1RA8qrF+Ms1RZv8gmzUnbyrPLmmZPmmN/Qs6DGzDVg73fpSwIDAQAB';//APP公钥
  1089. // $this->aop->apiVersion = '1.0';
  1090. // $this->aop->signType = 'RSA2';
  1091. // $this->aop->postCharset='UTF-8';
  1092. // $this->aop->format='json';
  1093. // //导入请求
  1094. // $request = new AlipayFundTransToaccountTransferRequest ();
  1095. // $request->setBizContent("{" .
  1096. // "\"out_biz_no\":\"".rand(1111111,99999999999999)."\"," .//商户生成订单号
  1097. // "\"payee_type\":\"ALIPAY_LOGONID\"," .//收款方支付宝账号类型
  1098. // "\"payee_account\":\"3089507753@qq.com\"," .//收款方账号
  1099. // "\"amount\":\"0.01\"," .//总金额
  1100. // "\"payer_show_name\":\"北京天地博爱科技有限公司\"," .//付款方账户
  1101. // "\"payee_real_name\":\"唐世伟\"," .//收款方姓名
  1102. // "\"remark\":\"测试转账\"" .//转账备注
  1103. // "}");
  1104. // $result = $this->aop->execute ( $request);
  1105. //
  1106. // dd($result);die;
  1107. // $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
  1108. // $resultCode = $result->$responseNode->code;
  1109. // if(!empty($resultCode)&&$resultCode == 10000){
  1110. // return true;
  1111. // } else {
  1112. // return false;
  1113. // }
  1114. }
  1115. /**
  1116. * 查单接口
  1117. */
  1118. public function query($order_number)
  1119. {
  1120. $this->aop = new AopClient ();
  1121. //配置参数
  1122. $this->init_aop_config();
  1123. $request = new \AlipayFundTransOrderQueryRequest ();
  1124. $request->setBizContent("{" .
  1125. "\"out_biz_no\":\"".$order_number."\"" .
  1126. " }");
  1127. $result = $this->aop->execute ( $request);
  1128. $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
  1129. $resultCode = $result->$responseNode->code;
  1130. if(!empty($resultCode)&&$resultCode == 10000){
  1131. $res_arr['code'] = '00';
  1132. $res_arr['data'] = $result;
  1133. } else {
  1134. $res_arr['code'] = '-1';
  1135. }
  1136. return $res_arr;
  1137. }
  1138. /**
  1139. * @return mixed
  1140. * @throws \think\db\exception\DataNotFoundException
  1141. * @throws \think\db\exception\DbException
  1142. * @throws \think\db\exception\ModelNotFoundException
  1143. * 分销中心
  1144. */
  1145. public function my_distributor()
  1146. {
  1147. $mer_id=$this->request->params(['mer_id']);
  1148. if(empty($mer_id['mer_id'])){
  1149. return app('json')->fail('请联系技术人员排查问题,感谢您的反馈');
  1150. }else{
  1151. $mer_id=$mer_id['mer_id'];
  1152. }
  1153. $uid= $uid=$this->request->uid();
  1154. $user_data=Db::name('entropy_barter_user_'.$mer_id)
  1155. ->alias('ebu')
  1156. ->join('user u','u.uid=ebu.uid')
  1157. ->where('ebu.uid',$uid)
  1158. ->field('ebu.*,u.nickname,u.avatar')
  1159. ->find();
  1160. if($user_data['avatar']=='https://cdn.bjtdba.com/chuxubao/static/assets/yhc_default_avatar.png'){
  1161. $user_data['avatar']=Db::name('user_account')->where('type',1)->where('uid',$uid)->value('avater');
  1162. if(empty($user_data['avatar'])){
  1163. $user_data['avatar']=Db::name('user_account')->where('type',2)->where('uid',$uid)->value('avater');
  1164. }
  1165. }
  1166. $user_data['top_name']=Db::name('entropy_barter_user_'.$mer_id)
  1167. ->alias('ebu')
  1168. ->leftJoin('user u','u.uid=ebu.uid')
  1169. ->where('ebu.eb_id',$user_data['top_eb_id'])
  1170. ->value('u.nickname')??'无';
  1171. //已提现佣金 包含未到账
  1172. $withdrawnCash=Db::name('entropy_barter_bill')->where('mer_id',$mer_id)->where('type',2)->where('to_id',$user_data['eb_id'])->where('status','2')->where('pm','2')->where('status','<>',3)->where('pm2_msg','提现')->sum('number');
  1173. //未结算佣金
  1174. $unsettledCommission=Db::name('entropy_barter_bill')
  1175. ->where('mer_id',$mer_id)
  1176. ->where('type',2)
  1177. ->where('to_id',$user_data['eb_id'])
  1178. ->where('pm',1)
  1179. ->where('status',1)
  1180. ->sum('number');
  1181. //未结算积分
  1182. $unsettled_integral=Db::name('entropy_barter_bill')
  1183. ->where('mer_id',$mer_id)
  1184. ->where('type',1)
  1185. ->where('to_id',$user_data['eb_id'])
  1186. ->where('pm',1)
  1187. ->where('status',1)
  1188. ->sum('number');
  1189. //分销佣金
  1190. $distributionCommission=bcadd($user_data['wallet'],$unsettledCommission,2);
  1191. //我的团队人数 一级 二级
  1192. $my_team=Db::name('entropy_barter_user_'.$mer_id)->where('top_eb_id',$user_data['eb_id'])->column('eb_id');
  1193. $my_team__number=Db::name('entropy_barter_user_'.$mer_id)->whereIn('top_eb_id',$my_team)->count('eb_id');
  1194. $my_team__number+=Db::name('entropy_barter_user_'.$mer_id)->where('top_eb_id',$user_data['eb_id'])->count('eb_id');
  1195. $data=[
  1196. 'user'=>$user_data,
  1197. 'withdrawnCash'=>bcadd($withdrawnCash,0,2),
  1198. 'unsettledCommission'=>bcadd($unsettledCommission,0,2),
  1199. 'distributionCommission'=>bcadd($distributionCommission,0,2),
  1200. 'my_team__number'=>$my_team__number,
  1201. 'unsettled_integral'=>$unsettled_integral
  1202. ];
  1203. return app('json')->success($data);
  1204. }
  1205. //商品列表
  1206. public function product_lst()
  1207. {
  1208. $mer_id=$this->request->params(['mer_id']);
  1209. if(empty($mer_id['mer_id'])){
  1210. return app('json')->fail('请联系技术人员排查问题,感谢您的反馈');
  1211. }else{
  1212. $mer_id=$mer_id['mer_id'];
  1213. }
  1214. [$page,$limit] = $this->getPage();
  1215. $cate_id=$this->request->params(['cate_id']);
  1216. $key=$this->request->params(['key']);
  1217. if(!empty($cate_id['cate_id'])) {
  1218. if(empty($key['key'])){
  1219. $data=Db::name('store_product_cate')->where('mer_cate_id',$cate_id['cate_id'])->where('mer_id',$mer_id)->column('product_id');
  1220. $data=Db::name('store_product')
  1221. ->where('mer_id',$mer_id)
  1222. ->where('is_show', 1)
  1223. ->where('is_used ', 1)
  1224. ->where('stock ', '>', 0)
  1225. ->where('product_id','in',$data)
  1226. ->page($page,$limit)
  1227. ->select();
  1228. }else{
  1229. $data=Db::name('store_product_cate')->where('mer_cate_id',$cate_id['cate_id'])->where('mer_id',$mer_id)->column('product_id');
  1230. $data=Db::name('store_product')
  1231. ->where('mer_id',$mer_id)
  1232. ->where('is_show', 1)
  1233. ->whereLike('store_name','%'.$key['key'].'%')
  1234. ->where('is_used ', 1)
  1235. ->where('stock ', '>', 0)
  1236. ->where('product_id','in',$data)
  1237. ->page($page,$limit)
  1238. ->select();
  1239. }
  1240. }else{
  1241. if(empty($key['key'])){
  1242. $data=Db::name('store_product')
  1243. ->where('mer_id',$mer_id)
  1244. ->where('is_show', 1)
  1245. ->where('is_used ', 1)
  1246. ->where('stock ', '>', 0)
  1247. ->page($page,$limit)
  1248. ->select();
  1249. }else{
  1250. $data=Db::name('store_product')
  1251. ->where('mer_id',$mer_id)
  1252. ->where('is_show', 1)
  1253. ->where('is_used ', 1)
  1254. ->where('stock ', '>', 0)
  1255. ->whereLike('store_name','%'.$key['key'].'%')
  1256. ->page($page,$limit)
  1257. ->select();
  1258. }
  1259. }
  1260. if($data->isEmpty()){
  1261. return app('json')->fail('暂无数据');
  1262. }
  1263. $data=$data->toArray();
  1264. foreach($data as $k=>&$v){
  1265. if($v['mer_id']==236){
  1266. $v['pension']=bcmul($v['price'],0.10,2);
  1267. }else{
  1268. $v['pension']=bcmul($v['price'],0.02,2);
  1269. }
  1270. }
  1271. return app('json')->success($data);
  1272. }
  1273. /**
  1274. * @return mixed
  1275. * @throws \think\db\exception\DataNotFoundException
  1276. * @throws \think\db\exception\DbException
  1277. * @throws \think\db\exception\ModelNotFoundException
  1278. * 提现 记录
  1279. */
  1280. public function withdrawal_details()
  1281. {
  1282. $mer_id=$this->request->params(['mer_id']);
  1283. if(empty($mer_id['mer_id'])){
  1284. return app('json')->fail('请联系技术人员排查问题,感谢您的反馈');
  1285. }else{
  1286. $mer_id=$mer_id['mer_id'];
  1287. }
  1288. $uid= $uid=$this->request->uid();
  1289. $user=Db::name('entropy_barter_user_'.$mer_id)->where('uid',$uid)->find();
  1290. if(empty($user)){
  1291. return app('json')->fail('暂无用户信息');
  1292. }
  1293. $data=Db::name('entropy_barter_bill')->where('mer_id',$mer_id)->where('from_id',$user['eb_id'])->where('pm','2')->where('pm2_msg','提现')
  1294. ->field('ctime,remarks,number,status')
  1295. ->select();
  1296. if($data->isEmpty()){
  1297. return app('json')->fail('暂无提现记录');
  1298. }
  1299. $data=$data->toArray();
  1300. foreach ($data as $k=>&$v){
  1301. $v['ctime']=date('Y-m-d H:i:s',$v['ctime']);
  1302. switch ($v['status']){
  1303. case 1:
  1304. $v['status']='提现中';
  1305. break;
  1306. case 2:
  1307. $v['status']='已提现';
  1308. break;
  1309. case 3:
  1310. $v['status']='已拒绝';
  1311. break;
  1312. }
  1313. }
  1314. return app('json')->success($data);
  1315. }
  1316. /**
  1317. * @return mixed
  1318. * @throws \think\db\exception\DataNotFoundException
  1319. * @throws \think\db\exception\DbException
  1320. * @throws \think\db\exception\ModelNotFoundException
  1321. * 商户分类
  1322. */
  1323. public function category()
  1324. {
  1325. $mer_id=$this->request->params(['mer_id']);
  1326. if(empty($mer_id['mer_id'])){
  1327. return app('json')->fail('请联系技术人员排查问题,感谢您的反馈');
  1328. }else{
  1329. $mer_id=$mer_id['mer_id'];
  1330. }
  1331. $cate=Db::name('store_category')->where('pid',0)->where('mer_id',$mer_id)->field('cate_name,store_category_id')->select();
  1332. if ($cate->isEmpty()){
  1333. return app('json')->fail('此商户没有分类');
  1334. }
  1335. $cate=$cate->toArray();
  1336. return app('json')->success($cate);
  1337. }
  1338. public function order_lst_yanglao()
  1339. {
  1340. $uid=$this->request->uid();
  1341. $mer_id=$this->request->params(['mer_id']);
  1342. if(empty($mer_id['mer_id'])){
  1343. return app('json')->fail('商户ID未传');
  1344. }
  1345. [$page,$limit] = $this->getPage();
  1346. $data=Db::name('store_order')->where('is_del','0')->where('paid',1)->page($page,$limit)->where('mer_id',$mer_id['mer_id'])->where('status','in','0,1,2,3')->where('uid',$uid)->select();
  1347. if($data->isEmpty()){
  1348. return app('json')->success([]);
  1349. }
  1350. $data=$data->toArray();
  1351. foreach ($data as $k=>&$v){
  1352. $goods_data=Db::name('store_order_product')
  1353. ->alias('sop')
  1354. ->leftJoin('store_product sp','sop.product_id=sp.product_id')
  1355. ->where('order_id',$v['order_id'])
  1356. ->field('sp.image,sp.store_name,sop.product_num,sop.product_price,sop.product_id')
  1357. ->find();
  1358. $v['product']=$goods_data;
  1359. $v['pension']=Db::name('user_bill')->where('uid',$uid)->where('source','0')->where('type_shop','0')->where(['link_id'=>$v['order_id']])->value('number');
  1360. }
  1361. return app('json')->success($data);
  1362. }
  1363. public function my_activation_code()
  1364. {
  1365. [$page, $limit] = $this->getPage();
  1366. $uid=$this->request->uid();
  1367. $code_data=Db::name('activation_code')
  1368. ->alias('ac')
  1369. ->where('ac.uid',$uid)
  1370. ->where('ac.status','>','0')
  1371. ->field('ac.code,ac.status as acstatus,ac.ctime as acctime,ac.utime as acutime,ac.uid as acuid,ac.id as acid,ac.use_uid')
  1372. ->page($page,$limit)
  1373. ->select()->toArray();
  1374. foreach ($code_data as $k=>&$v){
  1375. $v['use_user']=Db::name('user')->where('uid',$v['acuid'])->field('avatar,account,nickname')->find();
  1376. }
  1377. return app('json')->success($code_data);
  1378. }
  1379. //国腾名医单独处理
  1380. public function pay_orrder_290($order,$type)
  1381. {
  1382. $uid=$order['uid'];
  1383. $table_name='entropy_barter_user_290';
  1384. $order=Db::name('store_order')->where('order_sn',$order['order_no'])->find();
  1385. $order['order_no']=$order['order_sn'];
  1386. $product=DB::name('store_cart')->where('cart_id',$order['cart_id'])->value('product_id');
  1387. $imUserData=Db::name($table_name)->where('uid',$uid)->find();
  1388. $top_data=Db::name($table_name)->where('eb_id',$imUserData['top_eb_id'])->find();
  1389. if ($product=='362'||$product=='364'||$product=='363') {
  1390. Db::name('store_order')->where('order_sn',$order['order_no'])->update(['is_split_to_tomorrow'=>1,'status'=>3]);
  1391. if ($product == '362') {
  1392. Db::name($table_name)->where('eb_id', $imUserData['eb_id'])->update(['type' => 1, 'pay_goods_type' => 1,'pay_status'=>1]);
  1393. } else {
  1394. Db::name($table_name)->where('eb_id', $imUserData['eb_id'])->update(['type' => 2, 'pay_goods_type' => 2,'pay_status'=>1]);
  1395. }
  1396. }
  1397. /**
  1398. * 奖励模式开始
  1399. */
  1400. Db::name('user_bill')->where('order_sn',$order['order_no'])->where('uid',$order['uid'])->where('source',0)->update(['status'=>1]);
  1401. $order['money']=$order['pay_price'];
  1402. $eb_one=$this->one_jiangli($top_data,$order,$table_name,$type);
  1403. if(!$eb_one){
  1404. if($imUserData['pay_status']!=1){
  1405. $this->take_290($order['order_no'],1);
  1406. }else{
  1407. Db::name('log')->insert(['data'=>'已购买过合伙人商品或者创始人商品']);
  1408. }
  1409. return false;
  1410. }
  1411. //one_jiangli 推荐奖给了"它"
  1412. $eb_two=$this->two_jiangli($top_data,$order,$table_name,$type);
  1413. if(!$eb_two){
  1414. if($imUserData['pay_status']!=1){
  1415. $this->take_290($order['order_no'],1);
  1416. }else{
  1417. Db::name('log')->insert(['data'=>'已购买过合伙人商品或者创始人商品']);
  1418. }
  1419. return false;
  1420. }
  1421. //two_jiangli 推荐奖给了"它"
  1422. $eb_three=$this->three_jiangli($eb_two,$order,$table_name,$type);
  1423. if(!$eb_three){
  1424. if($imUserData['pay_status']!=1){
  1425. $this->take_290($order['order_no'],1);
  1426. }else{
  1427. Db::name('log')->insert(['data'=>'已购买过合伙人商品或者创始人商品']);
  1428. }
  1429. return false;
  1430. }
  1431. //three_jiangli 推荐奖给了"它"
  1432. if($eb_one['eb_id']==$eb_two['eb_id']){
  1433. $eb_four=$this->four_jiangli($eb_three,$order,$table_name,$type);
  1434. }
  1435. /**
  1436. * 奖励模式结束
  1437. */
  1438. }
  1439. //推荐奖
  1440. public function one_jiangli($top_data,$order,$table_name,$type)
  1441. {
  1442. // dd($top_data['pay_status']==1&&$top_data['type']>2);
  1443. if($top_data['pay_status']==1&&$top_data['type']>2){
  1444. $proportion=$this->reward_proportion($top_data['type']);
  1445. $money=bcmul($order['money'],"0.3",2);
  1446. $msg=$proportion['msg'].':推荐奖励';
  1447. $bill_data=[
  1448. 'from_id'=>0,
  1449. 'to_id'=>$top_data['eb_id'],
  1450. 'type'=>2,
  1451. 'order_no'=>$order['order_no'],
  1452. 'remarks'=>$msg,
  1453. 'ctime'=>time(),
  1454. 'number'=>$money,//商业合伙人或联合创始人奖励为30%
  1455. 'pm'=>1,
  1456. 'status'=>'2',
  1457. 'on_line'=>$type,
  1458. 'mer_id'=>290,
  1459. 'commission_type'=>1,
  1460. 'commission_scale'=>30,
  1461. 'to_user_type'=>1,
  1462. 'to_user_type_1'=>$proportion['type'],
  1463. ];
  1464. //增加账单记录
  1465. $this->eb_user_bill($bill_data);
  1466. Db::name($table_name)->where('eb_id',$top_data['eb_id'])->inc('wallet',$money)->update();
  1467. Db::name($table_name)->where('eb_id',$top_data['eb_id'])->inc('ranking_money',$money)->update();
  1468. $data=[
  1469. 'type'=>$top_data['type'],
  1470. 'eb_id'=>$top_data['eb_id']
  1471. ];
  1472. }
  1473. else{
  1474. // if($top_data['type']>=1){
  1475. // $money=bcmul($order['money'],"0.3",2);
  1476. // Db::name($table_name)->where('eb_id',$top_data['eb_id'])->inc('precipitate',$money)->update();
  1477. // $data=[
  1478. // 'type'=>$top_data['type'],
  1479. // 'eb_id'=>$top_data['eb_id']
  1480. // ];
  1481. // }
  1482. $data=[12313];
  1483. }
  1484. return $data;
  1485. }
  1486. //一级奖励
  1487. public function two_jiangli($top_data,$order,$table_name,$type)
  1488. {
  1489. // dd($top_data['type']>2);
  1490. if($top_data['type']>2){
  1491. $proportion=$this->reward_proportion($top_data['type']);
  1492. $money=bcmul($order['money'],$proportion['proportion'],2);
  1493. $msg=$proportion['msg'].':管理奖励';
  1494. $bill_data=[
  1495. 'from_id'=>0,
  1496. 'to_id'=>$top_data['eb_id'],
  1497. 'type'=>2,
  1498. 'order_no'=>$order['order_no'],
  1499. 'remarks'=>$msg,
  1500. 'ctime'=>time(),
  1501. 'number'=>$money,//商业合伙人或联合创始人奖励为30%
  1502. 'pm'=>1,
  1503. 'status'=>'2',
  1504. 'on_line'=>$type,
  1505. 'mer_id'=>290,
  1506. 'commission_type'=>1,
  1507. 'commission_scale'=>$proportion['proportion']*100,
  1508. 'to_user_type'=>2,
  1509. 'to_user_type_1'=>$proportion['type'],
  1510. ];
  1511. //增加账单记录
  1512. $this->eb_user_bill($bill_data);
  1513. Db::name($table_name)->where('eb_id',$top_data['eb_id'])->inc('wallet',$money)->update();
  1514. Db::name($table_name)->where('eb_id',$top_data['eb_id'])->inc('ranking_money',$money)->update();
  1515. $data=[
  1516. 'eb_id'=>$top_data['eb_id'],
  1517. 'type'=>$top_data['type']
  1518. ];
  1519. }else{
  1520. $top_1_id=$this->recursion_top($top_data['top_eb_id'],'0');
  1521. if($top_1_id==0){
  1522. return false;
  1523. }
  1524. $top_1_data=Db::name($table_name)->where('eb_id',$top_1_id)->find();
  1525. $proportion=$this->reward_proportion($top_1_data['type']);
  1526. $money=bcmul($order['money'],$proportion['proportion'],2);
  1527. $msg=$proportion['msg'].':管理奖励';
  1528. $bill_data=[
  1529. 'from_id'=>0,
  1530. 'to_id'=>$top_1_data['eb_id'],
  1531. 'type'=>2,
  1532. 'order_no'=>$order['order_no'],
  1533. 'remarks'=>$msg,
  1534. 'ctime'=>time(),
  1535. 'number'=>$money,//商业合伙人或联合创始人奖励为30%
  1536. 'pm'=>1,
  1537. 'status'=>'2',
  1538. 'on_line'=>$type,
  1539. 'mer_id'=>290,
  1540. 'commission_type'=>1,
  1541. 'commission_scale'=>$proportion['proportion']*100,
  1542. 'to_user_type'=>2,
  1543. 'to_user_type_1'=>$proportion['type'],
  1544. ];
  1545. //增加账单记录
  1546. $this->eb_user_bill($bill_data);
  1547. Db::name($table_name)->where('eb_id',$top_1_data['eb_id'])->inc('wallet',$money)->update();
  1548. Db::name($table_name)->where('eb_id',$top_1_data['eb_id'])->inc('ranking_money',$money)->update();
  1549. $data=[
  1550. 'type'=>$top_1_data['type'],
  1551. 'eb_id'=>$top_1_data['eb_id']
  1552. ];
  1553. }
  1554. return $data;
  1555. }
  1556. //二级奖励
  1557. public function three_jiangli($top_data,$order,$table_name,$type)
  1558. {
  1559. $top=$top_data;
  1560. $top_data=Db::name($table_name)->where('eb_id',$top['eb_id'])->find();
  1561. $top_top_data=Db::name($table_name)->where('eb_id',$top_data['top_eb_id'])->find();
  1562. //// dd($top_top_data>2);
  1563. // dd($top['type']==$top_top_data['type']||$top['type']>$top_top_data['type']);
  1564. if($top_top_data['type']>2){
  1565. if($top['type']==$top_top_data['type']||$top['type']>$top_top_data['type']){
  1566. $proportion=$this->reward_proportion($top_top_data['type']);
  1567. $proportion['proportion']='0.02';
  1568. $this->jiangli_cl($type,$order['money'],$order['order_no'],$top_top_data['eb_id'],$table_name,$proportion,3);
  1569. }elseif($top['type']<$top_top_data['type']){
  1570. if($top_top_data['type']==4){
  1571. $proportion=$this->reward_proportion($top_top_data['type']);
  1572. $proportion['proportion']='0.06';
  1573. $this->jiangli_cl($type,$order['money'],$order['order_no'],$top_top_data['eb_id'],$table_name,$proportion,3);
  1574. }elseif($top_top_data['type']==5){
  1575. if($top['type']==3){
  1576. $proportion=$this->reward_proportion($top_top_data['type']);
  1577. $proportion['proportion']='15';
  1578. $this->jiangli_cl($type,$order['money'],$order['order_no'],$top_top_data['eb_id'],$table_name,$proportion,3);
  1579. return false;
  1580. }else{
  1581. $proportion=$this->reward_proportion($top_top_data['type']);
  1582. $proportion['proportion']='0.09';
  1583. $this->jiangli_cl($type,$order['money'],$order['order_no'],$top_top_data['eb_id'],$table_name,$proportion,3);
  1584. }
  1585. }elseif($top_top_data['type']==3){
  1586. $proportion=$this->reward_proportion($top_top_data['type']);
  1587. $proportion['proportion']='0.03';
  1588. $this->jiangli_cl($type,$order['money'],$order['order_no'],$top_top_data['eb_id'],$table_name,$proportion,3);
  1589. }
  1590. }
  1591. $data=[
  1592. 'eb_id'=>$top_top_data['eb_id'],
  1593. 'type'=>$top_top_data['type']
  1594. ];
  1595. }else{
  1596. $top_1_id=$this->recursion_top($top_data['top_eb_id'],'0');
  1597. if($top_1_id==0){
  1598. return false;
  1599. }
  1600. $top_1_data=Db::name($table_name)->where('eb_id',$top_1_id)->find();
  1601. if($top['type']==$top_1_data['type']||$top['type']>$top_1_data['type']){
  1602. $proportion=$this->reward_proportion($top_1_data['type']);
  1603. $proportion['proportion']='0.02';
  1604. $this->jiangli_cl($type,$order['money'],$order['order_no'],$top_1_data['eb_id'],$table_name,$proportion,3);
  1605. }elseif($top['type']<$top_1_data['type']){
  1606. if($top_1_data['type']==4){
  1607. $proportion=$this->reward_proportion($top_1_data['type']);
  1608. $proportion['proportion']='0.06';
  1609. $this->jiangli_cl($type,$order['money'],$order['order_no'],$top_1_data['eb_id'],$table_name,$proportion,3);
  1610. }elseif($top_1_data['type']==5){
  1611. $proportion=$this->reward_proportion($top_1_data['type']);
  1612. $proportion['proportion']='0.09';
  1613. $this->jiangli_cl($type,$order['money'],$order['order_no'],$top_1_data['eb_id'],$table_name,$proportion,3);
  1614. }elseif($top_1_data['type']==3){
  1615. $proportion=$this->reward_proportion($top_1_data['type']);
  1616. $proportion['proportion']='0.02';
  1617. $this->jiangli_cl($type,$order['money'],$order['order_no'],$top_top_data['eb_id'],$table_name,$proportion,3);
  1618. }
  1619. }
  1620. $data=[
  1621. 'eb_id'=>$top_1_data['eb_id'],
  1622. 'type'=>$top_1_data['type']
  1623. ];
  1624. }
  1625. return $data;
  1626. }
  1627. //三级奖励
  1628. public function four_jiangli($top_data,$order,$table_name,$type)
  1629. {
  1630. $top=$top_data;
  1631. $top_data=Db::name($table_name)->where('eb_id',$top['eb_id'])->find();
  1632. $top_top_data=Db::name($table_name)->where('eb_id',$top_data['top_eb_id'])->find();
  1633. if(!$top_top_data){
  1634. return false;
  1635. }
  1636. if($top_top_data['type']>2){
  1637. if($top['type']<$top_top_data['type']){
  1638. if($top_top_data['type']==4){
  1639. $proportion=$this->reward_proportion($type);
  1640. $proportion['proportion']='0.06';
  1641. $this->jiangli_cl($type,$order['money'],$order['order_no'],$top_top_data['eb_id'],$table_name,$proportion,4);
  1642. }elseif($top_top_data['type']==5){
  1643. $proportion=$this->reward_proportion($type);
  1644. $proportion['proportion']='0.09';
  1645. $this->jiangli_cl($type,$order['money'],$order['order_no'],$top_top_data['eb_id'],$table_name,$proportion,4);
  1646. }elseif($top_top_data['type']==3){
  1647. $proportion=$this->reward_proportion($type);
  1648. $proportion['proportion']='0.03';
  1649. $this->jiangli_cl($type,$order['money'],$order['order_no'],$top_top_data['eb_id'],$table_name,$proportion,4);
  1650. }
  1651. }
  1652. $data=[
  1653. 'eb_id'=>$top_top_data['eb_id'],
  1654. 'type'=>$top_top_data['type']
  1655. ];
  1656. }else{
  1657. $top_1_id=$this->recursion_top($top_data['top_eb_id'],'0');
  1658. if($top_1_id==0){
  1659. return false;
  1660. }
  1661. $top_1_data=Db::name($table_name)->where('eb_id',$top_1_id)->find();
  1662. if($top['type']<$top_1_data['type']){
  1663. if($top_1_data['type']==4){
  1664. $proportion=$this->reward_proportion($top_1_data['type']);
  1665. $proportion['proportion']='0.06';
  1666. $this->jiangli_cl($type,$order['money'],$order['order_no'],$top_1_data['eb_id'],$table_name,$proportion,4);
  1667. $data=[
  1668. 'eb_id'=>$top_1_data['eb_id'],
  1669. 'type'=>$top_1_data['type']
  1670. ];
  1671. }elseif($top_1_data['type']==5){
  1672. $proportion=$this->reward_proportion($top_1_data['type']);
  1673. $proportion['proportion']='0.09';
  1674. $this->jiangli_cl($type,$order['money'],$order['order_no'],$top_1_data['eb_id'],$table_name,$proportion,4);
  1675. $data=[
  1676. 'eb_id'=>$top_1_data['eb_id'],
  1677. 'type'=>$top_1_data['type']
  1678. ];
  1679. }else{
  1680. return false;
  1681. }
  1682. }else{
  1683. return false;
  1684. }
  1685. }
  1686. return $data;
  1687. }
  1688. public function jiangli_cl($type,$money,$order_no,$eb_id,$table_name,$proportion,$to_user_type)
  1689. {
  1690. $money=bcmul($money,$proportion['proportion'],2);
  1691. $msg=$proportion['msg'].':管理奖励';
  1692. $bill_data=[
  1693. 'from_id'=>0,
  1694. 'to_id'=>$eb_id,
  1695. 'type'=>2,
  1696. 'order_no'=>$order_no,
  1697. 'remarks'=>$msg,
  1698. 'ctime'=>time(),
  1699. 'number'=>$money,//商业合伙人或联合创始人奖励为30%
  1700. 'pm'=>1,
  1701. 'status'=>'2',
  1702. 'on_line'=>$type,
  1703. 'mer_id'=>290,
  1704. 'commission_type'=>1,
  1705. 'commission_scale'=>$proportion['proportion']*100,
  1706. 'to_user_type'=>$to_user_type,
  1707. 'to_user_type_1'=>$proportion['type'],
  1708. ];
  1709. // dd($bill_data);
  1710. //增加账单记录
  1711. $this->eb_user_bill($bill_data);
  1712. Db::name($table_name)->where('eb_id',$eb_id)->inc('wallet',$money)->update();
  1713. Db::name($table_name)->where('eb_id',$eb_id)->inc('ranking_money',$money)->update();
  1714. }
  1715. //获取奖励比例
  1716. public function reward_proportion($type)
  1717. {
  1718. switch ($type){
  1719. case '3':
  1720. $proportion=[
  1721. "proportion"=>'0.03',
  1722. 'msg'=>'经理',
  1723. 'type'=>3,
  1724. ];
  1725. break;
  1726. case '4':
  1727. $proportion=[
  1728. "proportion"=>'0.09',
  1729. 'msg'=>'总监',
  1730. 'type'=>4,
  1731. ];
  1732. break;
  1733. case '5':
  1734. $proportion=[
  1735. "proportion"=>'0.18',
  1736. 'msg'=>'总裁',
  1737. 'type'=>5,
  1738. ];
  1739. break;
  1740. default:
  1741. case '2':
  1742. case '1':
  1743. $proportion=[
  1744. "proportion"=>'0',
  1745. 'msg'=>'其它',
  1746. 'type'=>0,
  1747. ];
  1748. }
  1749. return $proportion;
  1750. }
  1751. //国腾名医确认收货单独处理
  1752. public function take_290($order_no,$type=2)
  1753. {
  1754. Db::name('log')->insert(['data'=>'290进来了5']);
  1755. if($type==1){
  1756. $store_table_name='store_order';
  1757. $eb_table_name='entropy_barter_user_290';
  1758. $orde_data=Db::name($store_table_name)->where('order_sn',$order_no)->find();
  1759. $eb_data=Db::name($eb_table_name)->where('uid',$orde_data['uid'])->find();
  1760. // Db::name('user_bill')->where('order_sn',$order_no)->where('uid',$orde_data['uid'])->where('source',0)->update(['status'=>1]);
  1761. // $mer_id=Db::name('store_order')->where('order_sn',$order_no)->value('mer_id');
  1762. // $data=Db::name('entropy_barter_bill')->where('mer_id',$mer_id)->where('order_no',$order_no)->select();
  1763. // foreach ($data as $k=>$v){
  1764. // if($v['status']=='1'){
  1765. // if($v['type']==2){
  1766. // Db::name($eb_table_name)->where('eb_id',$v['to_id'])->inc('wallet',$v['number'])->update();
  1767. // Db::name($eb_table_name)->where('eb_id',$v['to_id'])->dec('integral',$v['number'])->update();
  1768. // Db::name('entropy_barter_bill')->where('id',$v['id'])->update(['status'=>2]);
  1769. // }elseif ($v['type']==1){
  1770. // Db::name($eb_table_name)->where('eb_id',$v['to_id'])->inc('integral',$v['number'])->update();
  1771. // Db::name('entropy_barter_bill')->where('id',$v['id'])->update(['status'=>2]);
  1772. // }
  1773. // }
  1774. // }
  1775. //特殊的地方开始处理了
  1776. //如果是特殊商品可以接着执行
  1777. $product_id=Db::name('store_cart')->where('cart_id',$orde_data['cart_id'])->value('product_id');
  1778. if($product_id==''){
  1779. return '';
  1780. }elseif ($product_id=='362'||$product_id=='364'||$product_id=='363'){
  1781. // Db::name('store_order')->where('order_sn',$order_no)->update(['is_split_to_tomorrow'=>1,'status'=>3]);
  1782. //查找上级是否可升级 $eb_data['top_eb_id']--上级ID
  1783. // if($product_id=='362'){
  1784. // Db::name($eb_table_name)->where('eb_id',$eb_data['eb_id'])->update(['type'=>2,'pay_goods_type'=>2]);
  1785. // }else{
  1786. // Db::name($eb_table_name)->where('eb_id',$eb_data['eb_id'])->update(['type'=>1]);
  1787. //
  1788. // }
  1789. $top_data=Db::name($eb_table_name)->where('eb_id',$eb_data['top_eb_id'])->find();
  1790. if($top_data['type']!=0){
  1791. Db::name('log')->insert(['data'=>'上级是会员']);
  1792. $this->recursion($top_data['eb_id']);
  1793. }else{
  1794. Db::name('log')->insert(['data'=>'上级不是会员'.$top_data['eb_id']]);
  1795. }
  1796. }
  1797. }
  1798. }
  1799. public function recursion($eb_id)
  1800. {
  1801. try {
  1802. $eb_table_name='entropy_barter_user_290';//1111
  1803. $eb_data=Db::name($eb_table_name)->where('eb_id',$eb_id)->find();
  1804. if($eb_data['type']==1){//一和二是同级别
  1805. $eb_data['type']=2;
  1806. }
  1807. if($eb_data['type']==0){
  1808. return '';
  1809. }
  1810. Db::name('guoteng_famous_doctor_relation')->insert(['uid'=>$eb_data['uid'],'type'=>$eb_data['type'],'create_time'=>date('Y-m-d H:i:s')]);
  1811. $top_upgrade_num=Db::name('guoteng_famous_doctor_relation')->where('type',$eb_data['type'])->where('uid',$eb_data['uid'])->count('id');
  1812. if($top_upgrade_num>=3){//如果该等级的数量大于3则升级
  1813. if($eb_data['type']==5){
  1814. return '已达到最高级别';
  1815. }
  1816. Db::name($eb_table_name)->where('uid',$eb_data['uid'])->update(['type'=>$eb_data['type']+1]);
  1817. if($eb_data['type']+1==3){
  1818. // $money=Db::name($eb_table_name)->where('uid',$eb_data['uid'])->value('precipitate');
  1819. $money=systemConfig('manager_reward');
  1820. $bill_data=[
  1821. 'from_id'=>0,
  1822. 'to_id'=>$eb_data['eb_id'],
  1823. 'type'=>2,
  1824. 'order_no'=>'0000000000000000',
  1825. 'remarks'=>'升级经理奖励',
  1826. 'ctime'=>time(),
  1827. 'number'=>$money,//商业合伙人或联合创始人奖励为30%
  1828. 'pm'=>1,
  1829. 'status'=>'2',
  1830. 'on_line'=>1,
  1831. 'mer_id'=>290,
  1832. 'commission_type'=>1,
  1833. 'commission_scale'=>0,
  1834. ];
  1835. //增加账单记录
  1836. $this->eb_user_bill($bill_data);
  1837. Db::name($eb_table_name)->where('eb_id',$eb_data['eb_id'])->inc('wallet',$money)->update();
  1838. Db::name($eb_table_name)->where('eb_id',$eb_data['eb_id'])->inc('ranking_money',$money)->update();
  1839. }
  1840. if($eb_data['top_eb_id']!=0){
  1841. $this->recursion($eb_data['top_eb_id']);
  1842. }else{
  1843. return '成功1';
  1844. }
  1845. }else{
  1846. return '小于3';
  1847. }
  1848. return '成功2';
  1849. }catch (\Exception $e) {
  1850. Db::name('log')->insert(['data'=>'订单支付出错:'.$e->getFile().':'.$e->getLine().'【'.$e->getMessage().'】']);
  1851. }
  1852. }
  1853. //提现手续费
  1854. public function withdrawal_service()
  1855. {
  1856. $data=$param=$this->request->param();
  1857. $money=$data['money']??'';
  1858. if($money==''){
  1859. return app('json')->fail('金额错误');
  1860. }
  1861. if($money=='.'){
  1862. return app('json')->fail('金额类型错误');
  1863. }
  1864. if( $this->source =='yhc') {
  1865. $yhc_withdrawal_rate=merchantConfig($this->merId,'yhc_withdrawal_rate');
  1866. $service_money=bcmul($money, $yhc_withdrawal_rate/100,2);
  1867. $money=bcsub($money,$service_money,2);
  1868. $service=$yhc_withdrawal_rate.'%';
  1869. }else{
  1870. $service_money=bcmul($money,'0.06',2);
  1871. $money=bcsub($money,$service_money,2);
  1872. $service='6%';
  1873. }
  1874. return app('json')->success(['service_money'=>$service_money,'money'=>$money,'service'=>$service]);
  1875. }
  1876. public function get_mp_access_token()
  1877. {
  1878. $access_token = Cache::get('wx9082e5ac2fdb513f1_mp_access_token');
  1879. if ($access_token)
  1880. return $access_token;
  1881. $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx9082e5ac2fdb513f&secret=88980d4455cd48e258c6bdff28029383";
  1882. $res = curlGet($url);
  1883. Cache::set('wx9082e5ac2fdb513f1_mp_access_token', $res['access_token'], $res['expires_in']);
  1884. return $res['access_token'];
  1885. }
  1886. public function getQrCode($pid, $uid,$mer_id)
  1887. {
  1888. $user = app()->make(\app\controller\merchant\user\User::class);
  1889. $access_token = $this->get_mp_access_token();
  1890. $url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" . $access_token;
  1891. $data['scene'] = 'spread=' . $uid . '&mer_id=' . $mer_id;
  1892. $data['page'] = 'pages/users/entranceList/entrance';
  1893. $res = $user->posturl($url, $data);
  1894. Db::name('log')->insert(['data'=>'小程序获取二维码'.json_encode($res)]);
  1895. //判断是否是 json格式
  1896. if (is_null(json_decode($res))) {
  1897. $new_file = (int)(microtime(true) * 1000);
  1898. $dir = iconv("UTF-8", "GBK", "./public/mpqrcode");
  1899. if (!file_exists($dir)) {
  1900. mkdir($dir, 0777, true);
  1901. }
  1902. $path = $dir . '/' . $new_file . ".jpg";
  1903. file_put_contents($path, $res);
  1904. $imgurl = env('APP_URL') . "/mpqrcode/" . $new_file . ".jpg";
  1905. return ['qrcode' => $imgurl, 'path' => $path];
  1906. } else {
  1907. //没有接收到数据流
  1908. return false;
  1909. }
  1910. }
  1911. public function share()
  1912. {
  1913. $mer_id = $this->request->params(['mer_id']);
  1914. $uid = $this->request->uid();
  1915. $mer_id = $mer_id['mer_id'] ?? '';
  1916. if ($mer_id == '') {
  1917. return app('json')->fail('请联系技术人员排查问题,感谢您的反馈');
  1918. }
  1919. $qrcode = $this->getQrCode('', $uid, $mer_id);
  1920. if (!$qrcode)
  1921. return app('json')->fail('获取小程序二维码失败');
  1922. $path = $qrcode['path'];
  1923. $qrcode = $qrcode['qrcode'];
  1924. $pdata['image']='https://app.bjtdba.com/applet/static/images/zjky/zjkyshare.png';
  1925. $pic_list = array(
  1926. $pdata['image'],
  1927. );
  1928. try {
  1929. $bg_w = 800; // 背景图片宽度
  1930. $bg_h = 1300; // 背景图片高度
  1931. $background = imagecreatetruecolor($bg_w, $bg_h); // 背景图片
  1932. imagecolorallocate($background, 0, 0, 0);
  1933. $red = imagecolorallocate($background, 255, 255, 255);
  1934. imagefill($background, 0, 0, $red);
  1935. $pic_count = count($pic_list);
  1936. $lineArr = array(); // 需要换行的位置
  1937. $space_x = 3;
  1938. $space_y = 3;
  1939. $line_x = 0;
  1940. switch ($pic_count) {
  1941. case 1: // 中间位置并排
  1942. $start_x = 0;
  1943. $start_y = 0;
  1944. $pic_w = intval($bg_w);
  1945. $pic_h = intval(800);
  1946. break;
  1947. }
  1948. foreach ($pic_list as $k => $pic_path) {
  1949. if (!strstr($pic_path, 'http')) {
  1950. $pic_path = 'https:' . $pic_path;
  1951. }
  1952. $kk = $k + 1;
  1953. if (in_array($kk, $lineArr)) {
  1954. $start_x = $line_x;
  1955. $start_y = $start_y + $pic_h + $space_y;
  1956. }
  1957. $pathInfo = pathinfo($pic_path);
  1958. switch (strtolower($pathInfo['extension'])) {
  1959. case 'jpg':
  1960. case 'jpeg':
  1961. $imagecreatefromjpeg = 'imagecreatefromjpeg';
  1962. break;
  1963. case 'png':
  1964. $imagecreatefromjpeg = 'imagecreatefrompng';
  1965. break;
  1966. case 'gif':
  1967. default:
  1968. $imagecreatefromjpeg = 'imagecreatefromstring';
  1969. $pic_path = file_get_contents($pic_path);
  1970. break;
  1971. }
  1972. $resource = $imagecreatefromjpeg($pic_path);
  1973. if ($k == 0) {
  1974. imagecopyresized($background, $resource, $start_x, $start_y, 0, 0, $pic_w, $pic_h, imagesx($resource), imagesy($resource)); // 最后两个参数为原始图片宽度和高度,倒数两个参数为copy时的图片宽度和高度
  1975. }
  1976. }
  1977. header("Content-type: image/jpg");
  1978. $filename1 = time();
  1979. $filename = './public/shareimg/' . $filename1 . '.png';
  1980. imagegif($background, $filename);
  1981. $filename = 'http://app.bjtdba.com/shareimg/' . $filename1 . '.png';
  1982. $filelink = [
  1983. 'Bold' => 'public/font/Alibaba-PuHuiTi-Regular.otf',
  1984. 'Normal' => 'public/font/Alibaba-PuHuiTi-Regular.otf',
  1985. ];
  1986. $config = array(
  1987. 'image' => array(
  1988. array(
  1989. 'url' => $qrcode,//二维码资源
  1990. 'stream' => 0,
  1991. 'left' => 147,
  1992. 'top' => 398,
  1993. 'right' => 0,
  1994. 'bottom' => 0,
  1995. 'width' => 300,
  1996. 'height' => 300,
  1997. 'opacity' => 100
  1998. )
  1999. ),
  2000. 'background' => $filename
  2001. );
  2002. $data = setSharePoster($config, 'routine/spread/poster');
  2003. unlink($path);
  2004. if (empty($data)) {
  2005. return app('json')->fail('生成海报失败请重新尝试');
  2006. }
  2007. return app('json')->success(['url'=>env('APP_URL') . $data['dir']]);
  2008. }catch (\Exception $e) {
  2009. unlink($path);
  2010. return app('json')->fail('生成海报失败请重新尝试');
  2011. }
  2012. }
  2013. //排行榜
  2014. public function ranking_list()
  2015. {
  2016. $mer_id = $this->request->params(['mer_id']);
  2017. $mer_id = $mer_id['mer_id'] ?? '';
  2018. if ($mer_id == '') {
  2019. return app('json')->fail('请联系技术人员排查问题,感谢您的反馈');
  2020. }
  2021. if($mer_id!=290){
  2022. return app('json')->fail('请联系技术人员排查问题,感谢您的反馈');
  2023. }
  2024. $data=Db::name('entropy_barter_user_290')->order('ranking_money','desc')->where('ranking_money','<>',0)->alias('ebu')->leftJoin('user u','u.uid=ebu.uid')->field('ranking_money as wallet,u.avatar,u.nickname')->select();
  2025. if($data->isEmpty()){
  2026. return app('json')->fail('数据正在回炉打造,马上就好');
  2027. }else{
  2028. $data=$data->toArray();
  2029. }
  2030. return app('json')->success($data);
  2031. }
  2032. public function zjky_signireward_record()
  2033. {
  2034. $mer_id = $this->request->params(['mer_id']);
  2035. $mer_id = $mer_id['mer_id'] ?? '';
  2036. if ($mer_id == '') {
  2037. return app('json')->fail('请联系技术人员排查问题,感谢您的反馈');
  2038. }
  2039. if($mer_id!=290){
  2040. return app('json')->fail('请联系技术人员排查问题,感谢您的反馈');
  2041. }
  2042. $uid=$this->request->uid();
  2043. $singin_time=time();
  2044. $find_data=Db::name('zjky_signireward_record')->where('member_id',$uid)->order('addtime','desc')->value('addtime');
  2045. if($find_data>strtotime(date('Ymd'))){
  2046. return app('json')->fail('今天已经签到过了');
  2047. }
  2048. Db::name('zjky_signireward_record')->insert(['member_id'=>$uid,'reward_socre'=>1,'signin_time'=>$singin_time,'addtime'=>time()]);
  2049. $now_score=Db::name('entropy_barter_user_290')->where('uid',$uid)->count('integral');
  2050. return app('json')->success(['code'=>0,'now_score'=>$now_score,'reward_socre'=>'1']);
  2051. }
  2052. public function get_zjky_signireward_record()
  2053. {
  2054. $mer_id = $this->request->params(['mer_id']);
  2055. $mer_id = $mer_id['mer_id'] ?? '';
  2056. if ($mer_id == '') {
  2057. return app('json')->fail('请联系技术人员排查问题,感谢您的反馈');
  2058. }
  2059. if($mer_id!=290){
  2060. return app('json')->fail('请联系技术人员排查问题,感谢您的反馈');
  2061. }
  2062. $uid=$this->request->uid();
  2063. $show_day_arr=Db::name('zjky_signireward_record')->where('member_id',$uid)->column('signin_time');
  2064. foreach ($show_day_arr as $k=>&$v){
  2065. $v=date('Y-m-d',$v);
  2066. }
  2067. $score=Db::name('zjky_signireward_record')->where('member_id',$uid)->sum('reward_socre');
  2068. $find_data=Db::name('zjky_signireward_record')->where('member_id',$uid)->order('addtime','desc')->value('addtime');
  2069. if($find_data>strtotime(date('Ymd'))){
  2070. $today_is_signin=1;
  2071. }else{
  2072. $today_is_signin=0;
  2073. }
  2074. return app('json')->success(['score'=>$score,'show_day_arr'=>$show_day_arr,'today_is_signin'=>$today_is_signin]);
  2075. }
  2076. //查找上级递归循环
  2077. public function recursion_top($eb_id,$my_type)
  2078. {
  2079. $data=Db::name('entropy_barter_user_290')->where('eb_id',$eb_id)->field('top_eb_id,eb_id,type,pay_status')->find();
  2080. if(!$data){
  2081. return 0;
  2082. }
  2083. if($data['pay_status']==1&&$data['type']>2){
  2084. // return $data['eb_id'];
  2085. return $data['eb_id'];
  2086. }elseif($data['pay_status']!=1||$data['type']<2){
  2087. return $this->recursion_top($data['top_eb_id'],$my_type);
  2088. }
  2089. }
  2090. }