| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214 |
- <?php
- /**
- * @package merchant
- *
- * @author xaboy
- * @day 2020-04-28
- *
- *
- */
- namespace app\common\repositories\user;
- use app\common\dao\BaseDao;
- use app\common\dao\user\UserDao;
- use app\common\model\merchant\order\OrderMerchant;
- use app\common\model\user\User;
- use app\common\model\wechat\WechatUser;
- use app\common\repositories\BaseRepository;
- use app\common\repositories\store\order\AgentOrderRepository;
- use app\common\repositories\store\order\StoreOrderRepository;
- use app\common\repositories\system\attachment\AttachmentRepository;
- use app\common\repositories\wechat\RoutineQrcodeRepository;
- use app\controller\api\store\product\Jd;
- use app\controller\api\store\product\Vip;
- use app\controller\api\user\Im;
- use app\traits\GzcApiRequest;
- use crmeb\exceptions\AuthException;
- use crmeb\jobs\SendNewPeopleCouponJob;
- use crmeb\services\JwtTokenService;
- use crmeb\services\QrcodeService;
- use crmeb\services\UploadService;
- use FormBuilder\Exception\FormBuilderException;
- use FormBuilder\Factory\Elm;
- use FormBuilder\Form;
- use think\Exception;
- use think\exception\ValidateException;
- use think\facade\Log;
- use think\facade\Queue;
- use function GuzzleHttp\Psr7\str;
- use think\db\exception\DataNotFoundException;
- use think\db\exception\DbException;
- use think\db\exception\ModelNotFoundException;
- use think\facade\Cache;
- use think\facade\Config;
- use think\facade\Db;
- use think\facade\Route;
- use think\Model;
- use app\controller\api\store\product\TaoKe;
- use alipay\aop\AopClient;
- use alipay\aop\request\AlipaySystemOauthTokenRequest;
- use alipay\aop\request\AlipayUserInfoShareRequest;
- /**
- * Class UserRepository
- * @package app\common\repositories\user
- * @author xaboy
- * @day 2020-04-28
- * @mixin UserDao
- */
- class UserRepository extends BaseRepository
- {
- use GzcApiRequest;
- /**
- * UserRepository constructor.
- * @param UserDao $dao
- */
- public function __construct(UserDao $dao)
- {
- $this->dao = $dao;
- }
- public function promoter($uid)
- {
- return $this->dao->update($uid, ['is_promoter' => 1, 'promoter_time' => date('Y-m-d H:i:s')]);
- }
- /**
- * 获取单条用户信息
- * @return array|\think\Model|null
- * @author php迷途小书童
- * @created 2021/1/16 10:45
- */
- public function getOne(array $where)
- {
- return ($this->dao->getWhere($where));
- }
- /**
- * @param $id
- * @return Form
- * @throws DataNotFoundException
- * @throws DbException
- * @throws FormBuilderException
- * @throws ModelNotFoundException
- * @author xaboy
- * @day 2020-05-09
- */
- public function userForm($id)
- {
- $user = $this->dao->get($id);
- $certification = Db::name('user_certification')->where("uid", $id)->find();
- $regions1 = Db::name('regions') -> field('id as value,name as label')->where('level',1) ->select();
- $regions2 = Db::name('regions') -> field('id as value,name as label,pid')->where('level',2) ->select();
- $regions3 = Db::name('regions') -> field('id as value,name as label,pid')->where('level',3) ->select();
- $regions3_data=[];
- foreach ($regions3 as $v){
- $regions3_data[$v['pid']][]=$v;
- }
- $regions2_data=[];
- foreach ($regions2 as $v){
- $v['children']=isset( $regions3_data[$v['value']])? $regions3_data[$v['value']]:[];
- $regions2_data[$v['pid']][]=$v;
- }
- $city_area=[];
- foreach ($regions1 as $v){
- $v['children']=isset( $regions2_data[$v['value']])? $regions2_data[$v['value']]:[];
- $city_area[]=$v;
- }
- $regions2_data2=[];
- foreach ($regions2 as $v){
- $regions2_data2[$v['pid']][]=$v;
- }
- $city_area_2=[];
- foreach ($regions1 as $v){
- $v['children']=isset( $regions2_data2[$v['value']])? $regions2_data2[$v['value']]:[];
- $city_area_2[]=$v;
- }
- $user['real_name'] = $certification['user_name'] ?? '';
- $user['card_id'] = $certification['user_card'] ?? '';
- $user['uid'] = (string)$user['uid'];
- $user_rich=Db::name('user_rich')->where('uid',$id)->find();
- $user['admin_start_level'] =$user_rich?$user_rich['admin_start_level']:'0';
- $user['user_rich_type'] =$user_rich?$user_rich['type']:'0';
- $user['area_manage_pics'] =[];
- $user['area_manage_obtain'] ='0';
- if($user_rich){
- $user['area_manage_obtain'] =$user_rich['obtain'];
- if($user_rich['pics']){
- $user['area_manage_pics']=explode(',',$user_rich['pics']);
- }
- }
- // $area_manage=Db::name('area_manage')->where('uid',$id)->find();
- $area_manage=null;
- // $area_manage_type=Db::name('area_manage')->where('uid',$id)->value('type');
- //类型 district-区/县代 city-市代',
- $user['area_manage_type'] ='0';
- $province = '';
- $city = '';
- $area = '';
- if($area_manage){
- if(isset($area_manage['type']) && $area_manage['type']=='district'){
- $user['area_manage_type']='1';
- }
- if(isset($area_manage['type']) && $area_manage['type']=='city'){
- $user['area_manage_type']='2';
- }
- $code_list=explode(',',$area_manage['code_list']);
- if(isset($code_list[0]) && $code_list[0]!=''){
- $province=$code_list[0];
- }
- if(isset($code_list[1]) && $code_list[1]!=''){
- $city=$code_list[1];
- }
- if(isset($code_list[2]) && $code_list[2]!=''){
- $area=$code_list[2];
- }
- }
- $where=[
- Elm::input('uid', '会员 ID', '')->disabled(true)->required(true),
- Elm::input('real_name', '真实姓名'),
- Elm::input('phone', '手机号'),
- Elm::date('birthday', '生日'),
- Elm::input('card_id', '身份证'),
- Elm::input('addres', '用户地址'),
- Elm::textarea('mark', '备注'),
- Elm::select('admin_start_level', '赠送消费星级')->options(function () {
- return array(
- array('value'=>'0','label'=>'普通用户'),
- array('value'=>'1','label'=>'1星级'),
- array('value'=>'2','label'=>'2星级'),
- array('value'=>'3','label'=>'3星级'),
- array('value'=>'4','label'=>'4星级'),
- array('value'=>'5','label'=>'5星级'),
- );
- })->className("tchakanquanyi"),
- Elm::select('user_rich_type', '身份')->options(function () {
- return array(
- array('value'=>'0','label'=>'请选择'),
- array('value'=>'1','label'=>'会员'),
- array('value'=>'4','label'=>'高级会员'),
- array('value'=>'8','label'=>'合伙人'),
- array('value'=>'3','label'=>'创始人'),
- array('value'=>'9','label'=>'联合创始人'),
- );
- }),
- Elm::select('area_manage_type', '代理')->options(function () {
- return array(
- array('value'=>'0','label'=>'请选择'),
- array('value'=>'1','label'=>'区/县代'),
- array('value'=>'2','label'=>'市代'),
- );
- })->control([ [
- 'value' => '1',
- 'rule' => [
- Elm::cityArea('city', '代理区域')->type('city_area')->options($city_area)->value([$province,$city,$area]),
- Elm::select('area_manage_obtain', '获得方式')->options(function () {
- return array(
- array('value'=>'0','label'=>'请选择'),
- array('value'=>'1','label'=>'线下支付'),
- array('value'=>'2','label'=>'赠送'),
- );
- })->control([[
- 'value'=>'1',
- 'rule'=>[
- Elm::frameImages('area_manage_pics', '支付凭证/截图', '/' . config('admin.admin_prefix') . '/setting/uploadPicture?field=area_manage_pics&type=2')
- ->width('896px')->height('480px')->modal(['modal' => false])->props(['footer' => false])
- ]
- ]])
- ]
- ],[
- 'value' => '2',
- 'rule' => [
- Elm::city('city', '代理区域')->type('city')->options($city_area_2)->value([$province,$city]),
- Elm::select('area_manage_obtain', '获得方式')->options(function () {
- return array(
- array('value'=>'0','label'=>'请选择'),
- array('value'=>'1','label'=>'线下支付'),
- array('value'=>'2','label'=>'赠送'),
- );
- })->control([[
- 'value'=>'1',
- 'rule'=>[
- Elm::frameImages('area_manage_pics', '支付凭证/截图', '/' . config('admin.admin_prefix') . '/setting/uploadPicture?field=area_manage_pics&type=2')
- ->width('896px')->height('480px')->modal(['modal' => false])->props(['footer' => false])
- ]
- ]])
- ]
- ]]),
- Elm::select('group_id', '会员分组')->options(function () {
- $data = app()->make(UserGroupRepository::class)->allOptions();
- $options = [];
- foreach ($data as $value => $label) {
- $options[] = compact('value', 'label');
- }
- return $options;
- }),
- Elm::selectMultiple('label_id', '会员标签')->options(function () {
- $data = app()->make(UserLabelRepository::class)->allOptions();
- $options = [];
- foreach ($data as $value => $label) {
- $value = (string)$value;
- $options[] = compact('value', 'label');
- }
- return $options;
- }),
- ];
- // 1 镇代 2 县代 3 市代 4 商户 5 推广员
- // $title="用户";
- // if ($user['identity']==1){
- // $title="镇代";
- // }
- // if ($user['identity']==2){
- // $title="县代";
- // }
- // if ($user['identity']==3){
- // $title="市代";
- // }
- // if ($user['identity']==4){
- // $title="商户";
- // }
- // if ($user['identity']==5){
- // $title="推广员";
- // }
- //
- // $where[] = Elm::text('identity', $title );
- if ($user['identity']!=0){
- $where[] =Elm::input('mer_rebate', "推荐商户返利");
- $where[] =Elm::input('promoter_rebate', "推荐代理返利");
- }
- if ($user['identity']==4){
- $where[] =Elm::input('agent_rebate', "推荐推广员返利");
- $where[] =Elm::input('cross_store', '跨店收入');
- }
- if ($user['identity']==1){
- $where[] =Elm::input('agent_rebate', "推荐推广员返利");
- // $title="镇代返利";
- // $where[] =Elm::input('jurisdiction', "辖区内收入");
- // $where[] =Elm::input('adv_fee', "广告费");
- $where[] =Elm::input('xqxiaofei', "自己辖区消费返利");
- }
- if ($user['identity']==2){
- $where[] =Elm::input('xqxiaofei', "自己辖区消费返利");
- $where[] =Elm::input('agent_rebate', "推荐推广员返利");
- $where[] =Elm::input('jurisdiction', "推荐其他区域代理费返佣:自己");
- $where[] =Elm::input('other_jurisdictions', "推荐其他区域代理费返佣:对应区域");
- }
- if ($user['identity']==3){
- $where[] =Elm::input('xqxiaofei', "自己辖区消费返利");
- $where[] =Elm::input('agent_rebate', "推荐推广员返利");
- $where[] =Elm::input('jurisdiction', "推荐其他区域代理费返佣:自己");
- $where[] =Elm::input('other_jurisdictions', "推荐其他区域代理费返佣:对应区域");
- }
- if ($user['identity']==5){
- $where[] =Elm::input('agent_rebate', "推荐推广员返利");
- }
- return Elm::createForm(Route::buildUrl('systemUserUpdate', compact('id'))->build(),$where )->setTitle('编辑')->formData($user->toArray());
- }
- /**
- * @param array $where
- * @param $page
- * @param $limit
- * @return array
- * @throws DataNotFoundException
- * @throws DbException
- * @throws ModelNotFoundException
- * @author xaboy
- * @day 2020-05-07
- */
- public function getAgent(array $where, $page, $limit)
- {
- //默认id排序
- $order = 'ua.id desc';
- if(isset($where['identity'])) {
- if ($where['identity'] == 1) {
- $order = 'u.identity asc';
- } elseif ($where['identity'] == 2) {
- $order = 'u.identity desc';
- }
- }
- $query = Db::name("user_agent")
- ->alias("ua")
- ->join("user u","u.uid=ua.user_id");
- if($where["keyword"]){
- $query = $query->whereLike("name","%".$where["keyword"]."%");
- }
- unset($where['keyword']);
- $list =$query->field("ua.*,u.nickname,u.avatar,u.avatar,u.brokerage_price,u.pay_count,u.spread_count,u.spread_uid")
- ->where($where)
- ->page($page, $limit)
- ->order($order)
- ->select()->toArray();
- $count = Db::name("user_agent")
- ->where($where)
- ->count();
- // $count =$query->where($where)->count();
- foreach($list as $k=>$value){
- $city['province'] = Db::name("user_province")->where(['province_id'=>$value['province_id']])->value("province_name");
- $city['city'] = Db::name("user_city")->where(['city_id'=>$value['city_id']])->value("city_name");
- $city['area'] = Db::name("user_area")->where(['area_id'=>$value['area_id']])->value("area_name");
- $city['street'] = Db::name("user_street")->where(['street_id'=>$value['street_id']])->value("street_name");
- $list[$k]['city'] = $city;
- }
- return compact('count', 'list');
- }
- /**
- * @param array $where
- * @param $page
- * @param $limit
- * @return array
- * @throws DataNotFoundException
- * @throws DbException
- * @throws ModelNotFoundException
- * @author xaboy
- * @day 2020-05-07
- */
- public function getAgentList(array $where, $page, $limit)
- {
- $wheres=[];
- $wheres['identity'] = [1,2,3,5,6];
- if($where["identity"]){
- $wheres["identity"]= $where['identity'];
- }
- $query =Db::name("user")->where($wheres);
- if($where["keyword"]){
- $query =$query->whereLike("account","%".$where['keyword']."%");
- }
- $list = $query ->field("account,uid,nickname,avatar,avatar,brokerage_price,pay_count,spread_count,spread_uid,identity")
- ->page($page, $limit)
- ->order("uid desc")
- ->select()->toArray();
- foreach($list as $k=>$value){
- $lis = Db::name("user")->where(['uid'=>$value['spread_uid']])->field("uid,account")->find();
- $list[$k]['spread'] =$lis;
- }
- $count_query = Db::name("user")->where($wheres);
- if($where["keyword"]){
- $count_query =$count_query->whereLike("account","%".$where['keyword']."%");
- }
- $count = $count_query->count();
- $wheres2=[];
- if ($where['keyword']){
- $wheres2[]=["account","like","%".$where['keyword']."%"];
- }
- $count1 = Db::name("user")->where($wheres2)->where("identity", 1 )->count();
- $count2 = Db::name("user")->where($wheres2)->where("identity", 2 )->count();
- $count3 = Db::name("user")->where($wheres2)->where("identity", 3 )->count();
- $count5 = Db::name("user")->where($wheres2)->where("identity", 5 )->count();
- $sart=[
- ['className'=> 'el-icon-s-goods', 'count'=>$count1, 'field'=>'人', 'name'=> '镇级服务商' ], [ 'className'=> 'el-icon-s-goods', 'count'=>$count2, 'field'=> '人', 'name'=>'县级服务商'], [ 'className'=> 'el-icon-s-order', 'count'=> $count3, 'field'=> '人', 'name'=> '市级服务商' ], [ 'className'=> 'el-icon-s-order', 'count'=> $count5, 'field'=> '人', 'name'=> '推广员' ]];
- // [{ 'className': 'el-icon-s-goods', 'count': '21.00', 'field': '元', 'name': '总支付金额' }, { 'className': 'el-icon-s-goods', 'count': '0.00', 'field': '元', 'name': '服务商返利' }, { 'className': 'el-icon-s-order', 'count': '3.24', 'field': '元', 'name': '养老金' }]
- return compact('count', 'list','sart','wheres');
- }
- public function getList(array $where, $page, $limit)
- {
- if(isset($where['user_card']) && $where['user_card'] !=''){
- $user_card = $where['user_card'];
- $query = $this->dao->search($where)->with(['spread' => function ($query) {
- $query->field('uid,account');
- }, 'group','certification' => function ($query) use ($user_card){
- $query->whereLike('user_card', "%".$user_card."%");
- }]);
- }else{
- $query = $this->dao->search($where)->with(['spread' => function ($query) {
- $query->field('uid,account');
- }, 'group','certification']);
- }
- $make = app()->make(UserLabelRepository::class);
- $count = $query->count('User.uid');
- $list = $query->page($page, $limit)->order("uid desc")->select()
- ->each(function ($item) use ($make) {
- $item->gzcAmount = 0;
- $item['lx'] = '';
- $vip = Db::name('da_cang_user') -> where('uid',$item['uid']) -> where('status',1) -> where('end_time','>',time())->value('type');
- if($vip == 1){
- $item['lx'] .= '【金卡会员】';
- }elseif ($vip == 2){
- $item['lx'] .= '【银卡会员】';
- }
- $channel = Db::name('channel_user') -> where('uid',$item['uid']) -> where('status',1) -> field('id') -> find();
- if($channel){
- $item['lx'] .= '【渠道商】';
- }
- //上级身份是否商户
- $is_shanghu1=Db::name('merchant_annual_cost_order')->where('status',1)->where('uid',$item['uid'])->find();
- $is_shanghu2=Db::name('merchant')->where('uid',$item['uid'])->find();
- $is_shanghu3=Db::name('merchant_intention')->where('uid',$item['uid'])->find();
- if($is_shanghu1||$is_shanghu2||$is_shanghu3){
- $item['lx'] .= '【商户】';
- }
- if(empty($item['lx'])){
- $item['lx'] = '普通用户';
- }
- // try {
- // $certification = Db::name('user_certification')
- // ->where('uid', $item->uid)
- // ->find();
- // if ($certification) {
- // $response = $this->checkAmount($certification);
- // $item->gzcAmount = $response['amount'];
- // }
- // } catch (\Throwable $w) {
- // $item->gzcAmount = 0;
- // }
- $item->label = count($item['label_id']) ? $make->labels($item['label_id']) : [];
- $user_rich=Db::name('user_rich')->where('uid', $item['uid'])->find();
- $item->is_huitian = (isset($user_rich) && $user_rich['is_huitian']==1)?true:false;
- $item->user_rich_type= (isset($user_rich) )?$user_rich['type']:0;
- $item->stockholder= (isset($user_rich) )?$user_rich['stockholder']:0;
- // $area_manage_type=Db::name('area_manage')->where('uid', $item['uid'])->value('type');
- //类型 district-区/县代 city-市代',
- $item->area_manage_type=$item['user_group'];
- $item->user_rich=$user_rich;
- $item->enterprise_user=Db::name('enterprise_user')->where('uid', $item['uid'])->select();
- foreach ($item->enterprise_user as $k=>$v){
- $p_phone=Db::name('user')->where('uid', $v['puid'])->value('phone');
- $v['p_phone']=$p_phone?$p_phone:'';
- $item->enterprise_user[$k]=$v;
- }
- return $item;
- });
- return compact('count', 'list');
- }
- public function getonePromoter(array $where){
- $data =Db::name("user_agent")
- ->where($where)
- ->find();
- $city['province'] = Db::name("user_province")->where(['province_id'=>$data['province_id']])->value("province_name");
- $city['city'] = Db::name("user_city")->where(['city_id'=>$data['city_id']])->value("city_name");
- $city['area'] = Db::name("user_area")->where(['area_id'=>$data['area_id']])->value("area_name");
- $city['street'] = Db::name("user_street")->where(['street_id'=>$data['street_id']])->value("street_name");
- $data['city'] = $city;
- return $data;
- }
- /*代理申请线下支付
- @cabbage
- */
- public function xianPayAgent($id,$mark=''){
- $user_agent=Db::name("user_agent")->where("id",$id)->order("add_time")->find();
- if(!$user_agent){
- return ['code'=>400,'msg'=>'信息有误'];
- }
- $agent_order = [
- 'type'=>4,
- 'price'=>$user_agent['price'],
- 'link_id'=>$user_agent['id'],
- 'identity'=>$user_agent['identity'],
- 'uid'=>$user_agent['user_id'],
- 'order_sn'=>(app()->make(AgentOrderRepository::class))->getNewOrderId("DL"),
- 'create_time'=>date('Y-m-d H:i:s'),
- 'mark'=>$mark
- ];
- $agentOrder = Db::name("agent_order")->insertGetId($agent_order);
- //支付成功回调状态
- return (app()->make(AgentOrderRepository::class))->paySuccess($agentOrder);
- }
- public function updateAgent(array $where,$id){
- $user_agent=Db::name("user_agent")->where("id",$id)->order("add_time")->find();
- //审核通过
- if ($where['status']==1){
- $user= Db::name("user")->where(['uid'=>$user_agent['user_id']])->value("identity");
- if($user['identity']==4){
- return ['code'=>400,'msg'=>'该用户已是商家,请拒绝'];
- }
- try{
- //判断所申请的区域下是否有代理,查询需要支付的代理费用
- if($user_agent['identity'] == 1){
- if(Db::name("user_street")->where("street_id",$user_agent['street_id'])->value("uid")){
- return ['code'=>400,'msg'=>'该区域下已有代理'];
- }
- $where_config['config_key'] = "agency_fee_zhen" ;
- }elseif($user_agent['identity'] == 2){
- if(Db::name("user_area")->where("area_id",$user_agent['area_id'])->value("uid")){
- return ['code'=>400,'msg'=>'该区域下已有代理'];
- }
- $where_config['config_key'] = "agency_fee_xian" ;
- }elseif($user_agent['identity'] == 3){
- if(Db::name("user_city")->where("city_id",$user_agent['city_id'])->value("uid")){
- return ['code'=>400,'msg'=>'该区域下已有代理'];
- }
- $where_config['config_key'] = "agency_fee_shi" ;
- }elseif($user_agent['identity'] == 5){
- $where_config['config_key'] = "agency_fee_tui" ;
- }elseif ($user_agent['identity'] == 6){
- $where_config['config_key'] = "agency_fee_qudao" ;
- }
- $config = Db::name("system_config_value")->where($where_config)->field("value")->find();
- $price = str_replace('"','',$config['value']);
- $price = (float)$price;
- Db::name("user_agent")->where("id",$id)->update(["status"=>1,"update_time"=>time(),'price'=>$price]);//修改申请信息
- //支付金额为0,直接创建成功记录
- if($price <= 0){
- $agent_order = [
- 'type'=>1,
- 'price'=>$price,
- 'link_id'=>$user_agent['id'],
- 'identity'=>$user_agent['identity'],
- 'uid'=>$user_agent['user_id'],
- 'order_sn'=>(app()->make(AgentOrderRepository::class))->getNewOrderId("DL"),
- 'create_time'=>date('Y-m-d H:i:s'),
- ];
- $agentOrder = Db::name("agent_order")->insertGetId($agent_order);
- //支付成功回调状态
- (app()->make(AgentOrderRepository::class))->paySuccess($agentOrder);
- }
- }catch (Exception $e) {
- Db::rollback();
- }
- }
- //审核拒绝
- if ($where['status']==2){
- $data['promoter_time'] = date('Y-m-d H:i:s');
- $data['identity']=0;
- $data['is_promoter']=0;
- Db::name("user")->where("uid",$user_agent["user_id"])->update($data);
- Db::name("user_agent")->where("id",$id)->update(["status"=>2,"update_time"=>time(),'pay_status'=>2]);
- }
- // if ($where['status']==2){
- // unset($data['is_promoter'],$data['promoter_time']);
- // Db::name("user_agent")->where("user_id",$id)->update(["status"=>2,"update_time"=>time()]);
- // }
- return true;
- }
- /**
- * 推广员推广成功获得佣金
- * @param $order
- */
- public function promoters($user_agent){
- //客户本人
- $order_user=Db::name("user")->where("uid",$user_agent["user_id"])->find();
- if ($user_agent["pid"]>0){
- //推广的人的信息
- $spread_identity=Db::name("user")->where("uid",$user_agent["pid"])->field("identity,agent_fee")->find();
- if ($spread_identity["identity"]>0){
- if (($spread_identity["identity"]!=2||$spread_identity["identity"]!=3)&&($order_user["county_agent"]==$user_agent["pid"])){
- $agent_fee=bcdiv($spread_identity["agent_fee"],100);
- $spread_fee=bcmul($user_agent["price"],$agent_fee) ;
- $title="代理费佣金";
- $mark ="获得代理费佣金".$spread_identity["agent_fee"]."%";
- $commission_type="1";
- $this->add_bill($title,$spread_fee,$user_agent["pid"],$mark,$commission_type,$order_user["agent_sn"]);
- }
- //用户本人的县代与当前推广的县代不一致(跨区域推广)
- if ($spread_identity["identity"]==2&&$order_user["county_agent"]!=$user_agent["pid"]&&$order_user["county_agent"]>0){
- //跨辖区用户对应推荐人佣金
- $agent_feezj=bcdiv($spread_identity["agent_fee3"],100);
- $agent_feezj=bcmul($user_agent["price"],$agent_feezj) ;
- $title="代理费佣金";
- $mark ="获得代理费佣金".$spread_identity["agent_fee3"]."%";
- $commission_type="1";
- $this->add_bill($title,$agent_feezj,$user_agent["pid"],$mark,$commission_type,$order_user["agent_sn"]);
- //跨辖区用户对应辖区佣金
- $spread_identity=Db::name("user")->where("uid",$order_user["county_agent"])->field("identity,agent_fee2")->find();
- $agent_fee=bcdiv($spread_identity["agent_fee2"],100);
- $spread_fee=bcmul($user_agent["price"],$agent_fee) ;
- $title="代理费佣金";
- $mark ="其他区域推荐代理费返佣".$spread_identity["agent_fee2"]."%";
- $commission_type="1";
- $this->add_bill($title,$spread_fee,$order_user["county_agent"],$mark,$commission_type,$order_user["agent_sn"]);
- }
- //用户本人的市代与当前推广的市代不一致(跨区域推广)
- if ($spread_identity["identity"]==3&&$order_user["city_agent"]!=$user_agent["pid"]&&$order_user["city_agent"]>0){
- //跨辖区用户对应推荐人佣金
- $agent_feezj=bcdiv($spread_identity["agent_fee3"],100);
- $agent_feezj=bcmul($user_agent["price"],$agent_feezj) ;
- $title="代理费佣金";
- $mark ="获得代理费佣金".$spread_identity["agent_fee3"]."%";
- $commission_type="1";
- $this->add_bill($title,$agent_feezj,$user_agent["pid"],$mark,$commission_type,$order_user["agent_sn"]);
- //跨辖区用户对应辖区佣金
- $spread_identity=Db::name("user")->where("uid",$order_user["county_agent"])->field("identity,agent_fee2")->find();
- $agent_fee=bcdiv($spread_identity["agent_fee2"],100);
- $spread_fee=bcmul($user_agent["price"],$agent_fee) ;
- $title="代理费佣金";
- $mark ="其他区域推荐代理费返佣".$spread_identity["agent_fee2"]."%";
- $commission_type="1";
- $this->add_bill($title,$spread_fee,$order_user["county_agent"],$mark,$commission_type,$order_user["agent_sn"]);
- }
- }
- }
- }
- /**
- * 佣金加入账单
- * @param $title
- * @param $number
- * @param $uid
- * @param $mark
- * @param $commission_type
- * @param $order_sn
- */
- public function add_bill($title,$number,$uid,$mark,$commission_type,$order_sn,$order_id=0){
- // $old_number=Db::name("user")->where("uid",$uid)->value("brokerage_price");
- $data=[
- 'link_id' => $order_id,
- "uid"=>$uid,
- // "pm"=>1,
- "title"=>$title,
- "category"=>"now_money",
- "type"=>"commission",
- "number"=>$number,
- "balance"=>0,
- "mark"=>$mark,
- "create_time"=>time(),
- "status"=>0,
- "commission_type"=>$commission_type,
- "order_sn"=>$order_sn,
- ];
- Db::name("user_bill")->insert($data);
- // Db::name("user")->where("uid",$uid)->inc('brokerage_price', $number) ->update();
- }
- public function merList(string $keyword, $page, $limit)
- {
- $query = $this->dao->searchMerUser($keyword);
- $count = $query->count($this->dao->getPk());
- $list = $query->page($page, $limit)->setOption('field', [])->field('uid,nickname,avatar,user_type,sex')->select();
- return compact('count', 'list');
- }
- /**
- * @param $id
- * @return Form
- * @throws DataNotFoundException
- * @throws DbException
- * @throws ModelNotFoundException
- * @throws FormBuilderException
- * @author xaboy
- * @day 2020-05-07
- */
- public function changeGroupForm($id)
- {
- $isArray = is_array($id);
- if (!$isArray)
- $user = $this->dao->get($id);
- /** @var UserGroupRepository $make */
- $data = app()->make(UserGroupRepository::class)->allOptions();
- return Elm::createForm(Route::buildUrl($isArray ? 'systemUserBatchChangeGroup' : 'systemUserChangeGroup', $isArray ? [] : compact('id'))->build(), [
- Elm::hidden('ids', $isArray ? $id : [$id]),
- Elm::select('group_id', '用户分组', $isArray ? '' : $user->group_id)->options(function () use ($data) {
- $options = [['label' => '不设置', 'value' => '0']];
- foreach ($data as $value => $label) {
- $options[] = compact('value', 'label');
- }
- return $options;
- })
- ])->setTitle('修改用户分组');
- }
- /**
- * @param $id
- * @return Form
- * @throws DataNotFoundException
- * @throws DbException
- * @throws ModelNotFoundException
- * @throws FormBuilderException
- * @author xaboy
- * @day 2020-05-07
- */
- public function changeLabelForm($id)
- {
- $isArray = is_array($id);
- if (!$isArray)
- $user = $this->dao->get($id);
- /** @var UserLabelRepository $make */
- $data = app()->make(UserLabelRepository::class)->allOptions();
- return Elm::createForm(Route::buildUrl($isArray ? 'systemUserBatchChangeLabel' : 'systemUserChangeLabel', $isArray ? [] : compact('id'))->build(), [
- Elm::hidden('ids', $isArray ? $id : [$id]),
- Elm::selectMultiple('label_id', '用户标签', $isArray ? [] : $user->label_id)->options(function () use ($data) {
- $options = [];
- foreach ($data as $value => $label) {
- $value = (string)$value;
- $options[] = compact('value', 'label');
- }
- return $options;
- })
- ])->setTitle('修改用户分组');
- }
- /**
- * @param $id
- * @return Form
- * @throws FormBuilderException
- * @author xaboy
- * @day 2020-05-07
- */
- public function changeNowMoneyForm($id)
- {
- return Elm::createForm(Route::buildUrl('systemUserChangeNowMoney', compact('id'))->build(), [
- Elm::radio('type', '修改余额', 1)->options([
- ['label' => '增加', 'value' => 1],
- ['label' => '减少', 'value' => 0],
- ])->required(),
- Elm::number('now_money', '金额')->required()->min(0)
- ])->setTitle('修改用户余额');
- }
- /**
- * @param $id
- * @return Form
- * @throws FormBuilderException
- * @author xaboy
- * @day 2020-05-07
- */
- public function changeProForm($id)
- {
- return Elm::createForm(Route::buildUrl('systemUserChangePro', compact('id'))->build(), [
- Elm::input('spread_account', '推荐人')->required()->placeholder("请填写推荐人手机号")
- ])->setTitle('修改用户推荐人');
- }
- public function changeProForm_yhc($id,$type=0)
- {
- if($type===1){
- return Elm::createForm(Route::buildUrl('systemUserChangePro', compact('id'))->build(), [
- Elm::input('spread_account', '业绩归属人账号')->required()->placeholder("请填写业绩归属人手机号")->info('修改业绩归属人后,用户业绩归属至所填写账号下,但邀请关系及其他邀请相关的奖励不变!'),
- Elm::hidden('type', '1')
- ])->setTitle('修改业绩归属人');
- }
- return Elm::createForm(Route::buildUrl('systemUserChangePro', compact('id'))->build(), [
- Elm::input('spread_account', '推荐人')->required()->placeholder("请填写推荐人手机号")
- ])->setTitle('修改用户推荐人');
- }
- /**
- * @param $id
- * @param $adminId
- * @param $type
- * @param $nowMoney
- * @throws DataNotFoundException
- * @throws DbException
- * @throws ModelNotFoundException
- * @author xaboy
- * @day 2020-05-07
- */
- public function changeNowMoney($id, $adminId, $type, $nowMoney)
- {
- $user = $this->dao->get($id);
- Db::transaction(function () use ($id, $adminId, $user, $type, $nowMoney) {
- $balance = $type == 1 ? bcadd($user->now_money, $nowMoney, 2) : bcsub($user->now_money, $nowMoney, 2);
- $user->save(['now_money' => $balance]);
- /** @var UserBillRepository $make */
- $make = app()->make(UserBillRepository::class);
- if ($type == 1) {
- $make->incBill($id, 'now_money', 'sys_inc_money', [
- 'link_id' => $adminId,
- 'status' => 1,
- 'title' => '系统增加余额',
- 'number' => $nowMoney,
- 'mark' => '系统增加了' . floatval($nowMoney) . '余额',
- 'balance' => $balance
- ]);
- } else {
- $make->decBill($id, 'now_money', 'sys_dec_money', [
- 'link_id' => $adminId,
- 'status' => 1,
- 'title' => '系统减少余额',
- 'number' => $nowMoney,
- 'mark' => '系统减少了' . floatval($nowMoney) . '余额',
- 'balance' => $balance
- ]);
- }
- });
- }
- /**
- * @param $password
- * @return false|string|null
- * @author xaboy
- * @day 2020/6/22
- */
- public function encodePassword($password)
- {
- return password_hash($password, PASSWORD_BCRYPT);
- }
- /**
- * @param WechatUser $wechatUser
- * @return BaseDao|array|Model|null
- * @throws DataNotFoundException
- * @throws DbException
- * @throws ModelNotFoundException
- * @author xaboy
- * @day 2020-04-28
- */
- public function syncWechatUser(WechatUser $wechatUser, $userType = 'wechat')
- {
- $user = $this->dao->wechatUserIdBytUser($wechatUser->wechat_user_id);
- $request = request();
- if ($user) {
- $user->save([
- 'nickname' => $wechatUser['nickname'] ?: '',
- 'avatar' => $wechatUser['headimgurl'] ?: '',
- 'sex' => $wechatUser['sex'] ?: 0,
- 'last_time' => date('Y-m-d H:i:s'),
- 'last_ip' => $request->ip(),
- ]);
- }
- // else
- // $user = $this->create($userType, [
- // 'account' => 'wx' . $wechatUser->wechat_user_id . time(),
- // 'wechat_user_id' => $wechatUser->wechat_user_id,
- // 'pwd' => $this->encodePassword(123456),
- // 'nickname' => $wechatUser['nickname'] ?: '',
- // 'avatar' => $wechatUser['headimgurl'] ?: '',
- // 'sex' => $wechatUser['sex'] ?: 0,
- // 'spread_uid' => 0,
- // 'is_promoter' => 0,
- // 'last_time' => date('Y-m-d H:i:s'),
- // 'last_ip' => $request->ip()
- // ]);
- return $user;
- }
- /**
- * @param string $type
- * @param array $userInfo
- * @param int $url 推广员的ID
- * @return BaseDao|Model
- * @author xaboy
- * @day 2020-04-28
- */
- public function create(string $type, array $userInfo, $url=0,$spread_uid=null)
- {
- $userInfo['user_type'] = $type;
- Db::startTrans();
- try {
- $user = $this->dao->create($userInfo); //创建用户
- $this -> insterUser($user->uid, $spread_uid);
- //唯品会pid
- // $vip = app()->make(Vip::class);
- // $vip->create_pid($user->uid);
- // //拼多多pid
- // $taoke = app()->make(TaoKe::class);
- // $taoke->generateAd($user->uid);
- // //京东pid(改成京京推推就)
- // $jd = app()->make(Jd::class);
- // $jd->create_pid($user->uid);
- //
- // Queue::push(SendNewPeopleCouponJob::class, $user->uid);
- Db::commit();
- return $user;
- } catch (\Exception $e) {
- Log::info($userInfo);
- Db::rollback();
- log::info("注册失败".$e->getFile().':'.$e->getLine().'【'.$e->getMessage().'】');
- throw new AuthException('注册失败');
- }
- }
- public function getUserLevelId($spread_uid){
- if (empty($spread_uid)){
- return false;
- }
- $sql = "select getUserLevelId($spread_uid) as count";
- $getUserLevelId = Db::query($sql);
- $user_level_uids=ltrim($getUserLevelId[0]['count'],'$,');
- return $user_level_uids;
- }
- public function insterUser($uid, $spread_uid){
- /**
- * 查询上级人数 select * from rrx_user_count LIMIT 0,1
- */
- // $spread_uid = Db::name('user') -> where('uid', $uid) -> value('spread_uid');
- // Db::name('log')->insert(['data'=>'公排注册:'.$uid.'======'.$spread_uid]);
- // $userCount = false;
- // if ($spread_uid > 0){
- // //找直推上级网络里面不足5人的排进去
- //
- // $userCount = Db::name('user_count') -> where('level_number >= 0') -> where ('uid', $spread_uid) -> find();
- // if (!$userCount){
- // $userCount = $this -> getCountUId($spread_uid);
- // }
- //
- //
- // }
- // Log::info("userCount:::");
- // Log::info($userCount);
- // Log::info($spread_uid);
- // Db::name('log')->insert(['data'=>'uid:'.$uid.'公排注册:'.json_encode($userCount)]);
- // if (!$userCount){
- // //没有直推上级 大公排
- // $userCount = Db::name('user_count') -> where('level_number >= 0') -> find();
- // //增加一个只查询新账户大公排下的用户
- // // $userCount = Db::name('user_count') -> where('level_number >= 0')->whereIn('uid',$this->getUserLevelId(11112)) -> find();
- // }
- // if ($userCount) {
- // if ($userCount['level_number'] + 1 == systemConfig( 'max_level_number')) { //(33制或者55制)下级最大人数systemConfig( 'max_level_number')
- // Db::name('user_count') -> where('uid',$userCount['uid'])->delete();
- // } else {
- // $level_number = $userCount['level_number'] + 1;
- // Db::name('user_count') -> where('uid',$userCount['uid']) -> update(['level_number'=>$level_number]);
- // }
- // }
- // dd($spread_uid);
- // Db::name('user') -> where('uid',$uid)->update(['level_id'=>$userCount['uid'],'level'=>$this->level()]);
- // Db::name('user_count') -> insert(['uid'=>$uid]);
- }
- public function getCountUId($spread_uid){
- if (empty($spread_uid)){
- return false;
- }
- //查询所有下级是否满足条件
- //查询所有下级uid
- $level_id = Db::name('user') -> where('level_id', $spread_uid) -> field('uid') -> select()->toArray();
- $level_ids = array_column($level_id,'uid');
- $check_ids = Db::name('user_count') -> where('level_number >= 0') -> where ('uid','in', $level_ids) -> find();
- foreach ($level_id as $value){
- //查询下级是否满足条件
- $check = Db::name('user_count') -> where('level_number >= 0') -> where ('uid', $value['uid']) -> find();
- if ($check){
- return $check;
- }else if(empty($check_ids)){
- $id = $this -> getCountUId($value['uid']);
- if ($id){
- return $id;
- }
- }
- }
- return false;
- }
- private function level() {
- $count = Db::name('user')->where('level > 0')->count();
- switch ($count) {
- case 0:
- return 1;
- case 1:
- return 2;
- }
- $number = ($count + 1) - floor($count / 5);
- return ceil(log($number) / log(5)) + 1;
- }
- /**
- * @param User $user
- * @return array
- * @author xaboy
- * @day 2020-04-29
- */
- public function createToken(User $user)
- {
- $service = new JwtTokenService();
- $token = $service->createToken($user->uid, 'user');
- $this->cacheToken($token['token'], $token['out'],$user->uid);
- if($user -> user_number == ''){
- $this -> createUserNumber($user->uid);
- }
- // if($user -> im == 0 && env('im',false)){
- // $im = new Im();
- // $im -> createIm($user -> account,$user -> user_number);
- // }
- return $token;
- }
- /**
- * //TODO 登录成功后
- * @param User $user
- * @author xaboy
- * @day 2020/6/22
- */
- public function loginAfter(User $user)
- {
- $user->last_time = date('Y-m-d H:i:s', time());
- $user->last_ip = request()->ip();
- $user->save();
- }
- /**
- * @param string $token
- * @param int $exp
- * @author xaboy
- * @day 2020-04-29
- */
- public function cacheToken(string $token, int $exp,$uid)
- {
- Cache::set('user_' . $token, time() + $exp, $exp);
- Cache::set('java_' . $token, $uid, $exp);
- }
- /**
- * @param string $token
- * @author xaboy
- * @day 2020-04-29
- */
- public function checkToken(string $token)
- {
- $has = Cache::has('user_' . $token);
- if (!$has)
- throw new AuthException('无效的token');
- $lastTime = Cache::get('user_' . $token);
- if (($lastTime + intval(Config::get('admin.token_valid_exp', 15)) * 60) > time())
- throw new AuthException('token 已过期');
- }
- /**
- * @param string $token
- * @author xaboy
- * @day 2020-04-29
- */
- public function updateToken(string $token)
- {
- Cache::set('user_' . $token, time(), intval(Config::get('admin.token_valid_exp', 15)) * 60);
- }
- /**
- * @param string $token
- * @author xaboy
- * @day 2020-04-29
- */
- public function clearToken(string $token)
- {
- Cache::delete('user_' . $token);
- }
- /**
- * @param string $key
- * @param string $code
- * @author xaboy
- * @day 2020/6/1
- */
- public function checkCode(string $key, string $code)
- {
- $_code = Cache::get('am_captcha' . $key);
- if (!$_code) {
- throw new ValidateException('验证码过期');
- }
- if (strtolower($_code) != strtolower($code)) {
- throw new ValidateException('验证码错误');
- }
- //删除code
- Cache::delete('am_captcha' . $key);
- }
- /**
- * @param string $code
- * @return string
- * @author xaboy
- * @day 2020/6/1
- */
- public function createLoginKey(string $code)
- {
- $key = uniqid(microtime(true), true);
- Cache::set('am_captcha' . $key, $code, Config::get('admin.captcha_exp', 5) * 60);
- return $key;
- }
- //$repository->registr($data['phone'], $data['password'],'APP',"","",$data['spread']);
- public function registr(string $phone, ?string $pwd, $user_type = 'h5',$url="",$nickname="",$external=1,$spread_uid=null)
- {
- $pwd = $pwd ? $this->encodePassword($pwd) : $this->encodePassword($this->dao->defaultPwd());
- $data = [
- 'account' => $phone,
- 'pwd' => $pwd,
- 'nickname' =>$nickname?$nickname:'用户' . substr($phone, 7, 4),
- 'avatar' => 'https://cdn.bjtdba.com/vod/image/2025-01-20/20250120125206881.png',
- 'phone' => $phone,
- 'last_ip' => app('request')->ip(),
- "identity"=>5,
- "external"=>$external,
- "level_id"=>$spread_uid,
- "spread_uid"=>$spread_uid
- ];
- return $this->create($user_type, $data, $url,$spread_uid);
- }
- public function addregistr($data)
- {
- // string $phone, ?string $pwd, $user_type = 'h5',$url,
- $phone=$data['phone'];
- $pwd=empty($data['password'])?time():$data['password'];
- $pwd = $pwd ? $this->encodePassword($pwd) : $this->encodePassword($this->dao->defaultPwd());
- $data = [
- 'account' => $phone,
- 'pwd' => $pwd,
- 'nickname' => '用户' . substr($phone, 7, 4),
- 'avatar' => 'https://cdn.bjtdba.com/chuxubao/static/assets/yhc_default_avatar.png',
- 'phone' => $phone,
- 'last_ip' => app('request')->ip(),
- 'user_name'=>empty($data['user_name'])?0:$data['user_name'],
- 'birthday'=>empty($data['birthday'])?0:$data['birthday'],
- 'sex'=>empty($data['adr_id'])?0:$data['sex'],
- 'spread_uid'=>$data['spread'],
- 'adr_id'=>empty($data['adr_id'])?0:$data["adr_id"],
- 'identity'=>empty($data['identity'])?0:$data["identity"],
- ];
- return $this->create("APP", $data);
- }
- /**
- * 重置密码
- * @param string $phone
- * @param string|null $pwd
- * @author 似水星辰 [ 2630481389@qq.com ]
- * @created 2020/10/14 23:46
- */
- public function resetPassword(string $phone, ?string $pwd, int $userid)
- {
- $pwd = $pwd ? $this->encodePassword($pwd) : $this->encodePassword($this->dao->defaultPwd());
- $data = [
- 'account' => $phone,
- 'pwd' => $pwd,
- 'phone' => $phone,
- 'last_ip' => app('request')->ip()
- ];
- return $this->dao->update($userid, $data);
- }
- /*重置手机号*/
- public function resetAccount(string $phone, int $userid, $identity){
- $data = [
- 'account' => $phone,
- 'phone' => $phone,
- 'last_ip' => app('request')->ip()
- ];
- //如果是商家
- if($identity == 4){
- $res = Db::name("merchant_admin")->where(['uid'=>$userid])->update(['account'=>$phone,'phone'=>$phone]);
- if(!$res){
- return false;
- }
- }
- return $this->dao->update($userid, $data);
- }
- public function routineSpreadImage(User $user)
- {
- //小程序
- $name = $user['uid'] . '_' . $user['is_promoter'] . '_user_routine.jpg';
- $attachmentRepository = app()->make(AttachmentRepository::class);
- $imageInfo = $attachmentRepository->getWhere(['attachment_name' => $name]);
- $spreadBanner = systemGroupData('spread_banner');
- if (!count($spreadBanner)) return [];
- $siteName = systemConfig('site_name');
- $siteUrl = systemConfig('site_url');
- $uploadType = (int)systemConfig('upload_type') ?: 1;
- //检测远程文件是否存在
- if (isset($imageInfo['attachment_src']) && strstr($imageInfo['attachment_src'], 'http') !== false && curl_file_exist($imageInfo['attachment_src']) === false) {
- $imageInfo->delete();
- $imageInfo = null;
- }
- if (!$imageInfo) {
- $routineQrcodeRepository = app()->make(RoutineQrcodeRepository::class);
- $res = $routineQrcodeRepository->getShareCode($user['uid'], 'spread', '',$user['avatar']);
- if (!$res) throw new ValidateException('二维码生成失败');
- $upload = UploadService::create($uploadType);
- $uploadRes = $upload->to('routine/spread/code')->validate()->stream($res['res'], $name);
- if ($uploadRes === false) {
- throw new ValidateException($upload->getError());
- }
- $imageInfo = $upload->getUploadInfo();
- $imageInfo['image_type'] = $uploadType;
- $imageInfo['dir'] = path_to_url($imageInfo['dir']);
- if (strpos($imageInfo['dir'], 'http') === false) $imageInfo['dir'] = request()->domain() . $imageInfo['dir'];
- $attachmentRepository->create($uploadType, -1, $user->uid, [
- 'attachment_category_id' => 0,
- 'attachment_name' => $imageInfo['name'],
- 'attachment_src' => $imageInfo['dir']
- ]);
- $routineQrcodeRepository->setRoutineQrcodeFind($res['id'], ['status' => 1, 'url_time' => date('Y-m-d H:i:s'), 'qrcode_url' => $imageInfo['dir']]);
- $urlCode = $imageInfo['dir'];
- } else $urlCode = $imageInfo['attachment_src'];
- $siteUrlHttps = set_http_type($siteUrl, request()->isSsl() ? 0 : 1);
- $filelink = [
- 'Bold' => 'public/font/Alibaba-PuHuiTi-Regular.otf',
- 'Normal' => 'public/font/Alibaba-PuHuiTi-Regular.otf',
- ];
- if (!file_exists($filelink['Bold'])) throw new ValidateException('缺少字体文件Bold');
- if (!file_exists($filelink['Normal'])) throw new ValidateException('缺少字体文件Normal');
- $resRoutine = true;
- foreach ($spreadBanner as $key => &$item) {
- $posterInfo = '海报生成失败:(';
- $config = array(
- 'image' => array(
- array(
- 'url' => $urlCode, //二维码资源
- 'stream' => 0,
- 'left' => 114,
- 'top' => 790,
- 'right' => 0,
- 'bottom' => 0,
- 'width' => 120,
- 'height' => 120,
- 'opacity' => 100
- )
- ),
- 'text' => array(
- array(
- 'text' => $user['nickname'],
- 'left' => 250,
- 'top' => 840,
- 'fontPath' => $filelink['Bold'], //字体文件
- 'fontSize' => 16, //字号
- 'fontColor' => '40,40,40', //字体颜色
- 'angle' => 0,
- ),
- array(
- 'text' => '邀请您加入' . $siteName,
- 'left' => 250,
- 'top' => 880,
- 'fontPath' => $filelink['Normal'], //字体文件
- 'fontSize' => 16, //字号
- 'fontColor' => '40,40,40', //字体颜色
- 'angle' => 0,
- )
- ),
- 'background' => $item['pic']
- );
- $resRoutine = $resRoutine && $posterInfo = setSharePoster($config, 'routine/spread/poster');
- if (!is_array($posterInfo)) throw new ValidateException($posterInfo);
- $posterInfo['dir'] = path_to_url($posterInfo['dir']);
- if (strpos($posterInfo['dir'], 'http') === false) $posterInfo['dir'] = request()->domain() . $posterInfo['dir'];
- $attachmentRepository->create($uploadType, -1, $user->uid, [
- 'attachment_category_id' => 0,
- 'attachment_name' => $posterInfo['name'],
- 'attachment_src' => $posterInfo['dir']
- ]);
- if ($resRoutine) {
- if ($posterInfo['image_type'] == 1)
- $item['poster'] = rtrim($siteUrlHttps, '/') . $posterInfo['dir'];
- else
- $item['poster'] = set_http_type($posterInfo['dir'], request()->isSsl() ? 0 : 1);
- $item['poster'] = str_replace('\\', '/', $item['poster']);
- }
- }
- return $spreadBanner;
- }
- public function wxSpreadImage(User $user)
- {
- //公众号
- $name = $user['uid'] . '_' . $user['is_promoter'] . '_user_wap.jpg';
- $spreadBanner = systemGroupData('spread_banner');
- if (!count($spreadBanner)) return [];
- $siteName = systemConfig('site_name');
- $attachmentRepository = app()->make(AttachmentRepository::class);
- $imageInfo = $attachmentRepository->getWhere(['attachment_name' => $name]);
- $siteUrl = systemConfig('site_url');
- $uploadType = (int)systemConfig('upload_type') ?: 1;
- $resWap = true;
- //检测远程文件是否存在
- if (isset($imageInfo['attachment_src']) && strstr($imageInfo['attachment_src'], 'http') !== false && curl_file_exist($imageInfo['attachment_src']) === false) {
- $imageInfo->delete();
- $imageInfo = null;
- }
- if (!$imageInfo) {
- $codeUrl = set_http_type($siteUrl . '/share?spread=' . $user['uid'], request()->isSsl() ? 0 : 1);//二维码链接
- $imageInfo = app()->make(QrcodeService::class)->getQRCodePath($codeUrl, $name,$user['avatar']);
- if (is_string($imageInfo)) throw new ValidateException('二维码生成失败');
- $imageInfo['dir'] = path_to_url($imageInfo['dir']);
- if (strpos($imageInfo['dir'], 'http') === false) $imageInfo['dir'] = request()->domain() . $imageInfo['dir'];
- $attachmentRepository->create(systemConfig('upload_type') ?: 1, -1, $user->uid, [
- 'attachment_category_id' => 0,
- 'attachment_name' => $imageInfo['name'],
- 'attachment_src' => $imageInfo['dir']
- ]);
- $urlCode = $imageInfo['dir'];
- } else $urlCode = $imageInfo['attachment_src'];
- $siteUrl = set_http_type($siteUrl, request()->isSsl() ? 0 : 1);
- $filelink = [
- 'Bold' => 'public/font/Alibaba-PuHuiTi-Regular.otf',
- 'Normal' => 'public/font/Alibaba-PuHuiTi-Regular.otf',
- ];
- if (!file_exists($filelink['Bold'])) throw new ValidateException('缺少字体文件Bold');
- if (!file_exists($filelink['Normal'])) throw new ValidateException('缺少字体文件Normal');
- foreach ($spreadBanner as $key => &$item) {
- $posterInfo = '海报生成失败:(';
- $config = array(
- 'image' => array(
- array(
- 'url' => $urlCode, //二维码资源
- 'stream' => 0,
- 'left' => 160,//84
- 'top' => 530,//630
- 'right' => 0,
- 'bottom' => 0,
- 'width' => 280,
- 'height' => 280,
- 'opacity' => 100
- )
- ),
- 'text' => array(
- array(
- 'text' => "NO:".$user['user_number'],
- 'left' => 200,
- 'top' => 850,
- 'fontPath' => $filelink['Bold'], //字体文件
- 'fontSize' => 16, //字号
- 'fontColor' => '0,0,0', //字体颜色
- 'angle' => 0,
- ),
- // array(
- // 'text' => '邀请您加入' . $siteName,
- // 'left' => 290,
- // 'top' => 750,
- // 'fontPath' => $filelink['Normal'], //字体文件
- // 'fontSize' => 16, //字号
- // 'fontColor' => '40,40,40', //字体颜色
- // 'angle' => 0,
- // )
- ),
- 'background' => $item['pic']
- );
- $resWap = $resWap && $posterInfo = setSharePoster($config, 'wap/spread/poster');
- if (!is_array($posterInfo)) throw new ValidateException('海报生成失败');
- $posterInfo['dir'] = path_to_url($posterInfo['dir']);
- if (strpos($posterInfo['dir'], 'http') === false) $posterInfo['dir'] = request()->domain() . $posterInfo['dir'];
- $attachmentRepository->create($uploadType, -1, $user->uid, [
- 'attachment_category_id' => 0,
- 'attachment_name' => $posterInfo['name'],
- 'attachment_src' => $posterInfo['dir']
- ]);
- if ($resWap) {
- if ($posterInfo['image_type'] == 1)
- $item['wap_poster'] = rtrim($siteUrl, '/') . $posterInfo['thumb_path'];
- else
- $item['wap_poster'] = set_http_type($posterInfo['thumb_path'], 1);
- }
- $item['wap_poster'] = str_replace('http://','https://',$item['wap_poster']);
- $item["attachment_src"]= str_replace('http://','https://',$urlCode);
- $item["name"]=$user['phone'];
- }
- return $spreadBanner;
- }
- public function getUsername($uid)
- {
- return User::getDB()->where('uid', $uid)->value('user_name');
- }
- /*获取用户手机号*/
- public function getUserPhone($uid)
- {
- return User::getDB()->where('uid', $uid)->value('account');
- }
- /**
- * @param $uid
- * @param $inc
- * @param string $type
- * @author xaboy
- * @day 2020/6/22
- */
- public function incBrokerage($uid, $inc, $type = '+')
- {
- $weekKey = 'b_top_' . date('Y-m');
- $moneyKey = 'b_top_' . monday();
- //TODO 佣金周榜
- $brokerage = Cache::zscore($weekKey, $uid);
- $brokerage = $type == '+' ? bcadd($brokerage, $inc, 2) : bcsub($brokerage, $inc, 2);
- Cache::zadd($weekKey, $brokerage, $uid);
- //TODO 佣金月榜
- $brokerage = Cache::zscore($moneyKey, $uid);
- $brokerage = $type == '+' ? bcadd($brokerage, $inc, 2) : bcsub($brokerage, $inc, 2);
- Cache::zadd($moneyKey, $brokerage, $uid);
- }
- public function brokerageWeekTop($page, $limit)
- {
- $key = 'b_top_' . monday();
- return $this->topList($key, $page, $limit);
- }
- public function brokerageMonthTop($page, $limit)
- {
- $key = 'b_top_' . date('Y-m');
- return $this->topList($key, $page, $limit);
- }
- /**
- * //TODO 绑定上下级关系
- * @param User $user
- * @param int $spreadUid
- * @throws DbException
- * @author xaboy
- * @day 2020/6/22
- */
- public function bindSpread(User $user, int $spreadUid)
- {
- if ($spreadUid && !$user->spread_uid && $user->uid != $spreadUid) {
- Db::transaction(function () use ($spreadUid, $user) {
- $spread_user = $this ->get($spreadUid);
- //首次邀请赠送899积分
- if($spread_user['spread_count'] == 0){
- //首次邀请好友奖励积分
- $this -> sign_add($spreadUid,systemConfig('first_yq_score'),1,'首次邀请好友奖励积分','','');
- }
- //邀请好友奖励积分
- $this -> sign_add($spreadUid,systemConfig('invitation'),1,'邀请好友注册奖励积分','','');
- $user->spread_uid = $spreadUid;
- $user->spread_time = date('Y-m-d H:i:s');
- if($spreadUid){
- $user->mer_id = Db::name('user')->where('uid',$spreadUid)->value('mer_id');
- }
- $this->dao->update($spreadUid, [
- 'spread_count' => Db::raw('spread_count +1')
- ]);
- $user->save();
- //TODO 推广人月榜
- Cache::zincrby('s_top_' . date('Y-m'), 1, $spreadUid);
- //TODO 推广人周榜
- Cache::zincrby('s_top_' . monday(), 1, $spreadUid);
- });
- $this->spread_log($user,$spreadUid);
- }
- //绑定上下级关系 加入推广群
- // $this -> hximTg($user -> uid,$spreadUid);
- }
- /**
- * @param $uid int 用户id
- * @param $sid int 上级id
- * @author Tang
- * @created 2021/12/10
- */
- public function hximTg($uid,$sid)
- {
- try {
- $im=new Im();
- $user=Db::name('user')->where('uid',$uid)->find();
- if($user['im']==0){//没有环信账户 创建
- $im->createImUser($user['account'], $user['nickname']);
- $user_account=$user['account'];
- }else{//有环信账户 跳过创建 下一步
- $user_account=$user['account'];
- }
- $userS=Db::name('user')->where('uid',$sid)->find();
- if($userS['im']==0){//上级环信账户 创建
- $im->createImUser($userS['account'], $userS['nickname']);
- $s_account=$userS['account'];
- }else{//有环信账户 跳过创建 下一步
- $s_account=$userS['account'];
- }
- $group_id=Db::name("im_group")->where(['uid'=>$userS['account'],'type'=>'p'])->value('groupid');
- //判断是否有群
- if($group_id){//有则加入
- $im->createGroupUser($group_id,$user_account,$user['uid']);
- }else{
- $group_id=$im->createGroup($s_account,'推广群','t');
- $im->createGroupUser($group_id,$user_account,$user['uid']);
- }
- }catch (\Exception $e) {
- Db::name("log")->insert(array('data'=>'推广群错误'.$e->getMessage()));//日志记录
- }
- }
- //注册时成为推广员身份 记录统计及信息
- public function spread_log($user,$spreadUid){
- if($spreadUid){
- Db::transaction(function () use ($spreadUid, $user) {
- $sp = DB::name("user")->where(['uid'=>$spreadUid])->field("uid,spread_count")->find();
- if($sp){
- //推荐人推荐数量加1
- Db::name("user")->where(['uid'=>$sp['uid']])->update(['spread_count'=>($sp['spread_count']+1)]);
- //保存用户的推荐记录
- $log =[
- 'uid'=> $sp['uid'],
- 'link_id'=>$user->uid,
- 'identity'=>5,
- 'create_time'=>date("Y-m-d H:i:s"),
- ] ;
- Db::name("user_identity_log")->insert($log);
- }
- });
- }
- }
- public function topList($key, $page, $limit)
- {
- $res = Cache::zrevrange($key, ($page - 1) * $limit, $limit, true);
- $ids = array_keys($res);
- $index = array_flip($ids);
- $count = Cache::zcard($key);
- $list = count($ids) ? $this->dao->users($ids, 'uid,avatar,nickname')->toArray() : [];
- foreach ($list as $k => $v) {
- $list[$k]['count'] = $res[$v['uid']] ?? 0;
- }
- $sort = array_column($list, 'count');
- array_multisort($sort, SORT_DESC, $list);
- return compact('count', 'list');
- }
- public function spreadWeekTop($page, $limit)
- {
- $key = 's_top_' . monday();
- return $this->topList($key, $page, $limit);
- }
- public function spreadMonthTop($page, $limit)
- {
- $key = 's_top_' . date('Y-m');
- return $this->topList($key, $page, $limit);
- }
- /**
- * @param $uid
- * @param $nickname
- * @param $sort
- * @param $page
- * @param $limit
- * @return array
- * @throws DataNotFoundException
- * @throws DbException
- * @throws ModelNotFoundException
- * @author xaboy
- * @day 2020/6/22
- */
- public function getOneLevelList($uid, $nickname, $sort, $page, $limit)
- {
- $query = $this->search(['spread_uid' => $uid, 'nickname' => $nickname, 'sort' => $sort]);
- $count = $query->count();
- $list = $query->setOption('field', [])->field('uid,avatar,nickname,pay_count,pay_price,spread_count,spread_time')->page($page, $limit)->select();
- return compact('list', 'count');
- }
- /**
- * @param $uid
- * @param $nickname
- * @param $sort
- * @param $page
- * @param $limit
- * @return array
- * @throws DataNotFoundException
- * @throws DbException
- * @throws ModelNotFoundException
- * @author xaboy
- * @day 2020/6/22
- */
- public function getTwoLevelList($uid, $nickname, $sort, $page, $limit)
- {
- $ids = $this->dao->getSubIds($uid);
- if (count($ids)) {
- $query = $this->search(['spread_uids' => $ids, 'nickname' => $nickname, 'sort' => $sort]);
- $count = $query->count();
- $list = $query->setOption('field', [])->field('uid,avatar,nickname,pay_count,pay_price,spread_count,spread_time')->page($page, $limit)->select();
- } else {
- $list = [];
- $count = 0;
- }
- return compact('list', 'count');
- }
- public function getLevelList($uid, array $where, $page, $limit)
- {
- if (!$where['level']) {
- // $ids = $this->dao->getSubIds($uid);
- $ids[] = $uid;
- $where['spread_uids'] = $ids;
- } else if ($where['level'] == 2) {
- $ids = $this->dao->getSubIds($uid);
- if (!count($ids)) return ['list' => [], 'count' => 0];
- $where['spread_uids'] = $ids;
- } else {
- $where['spread_uid'] = $uid;
- }
- $query = $this->search($where);
- $count = $query->count();
- $list = $query->setOption('field', [])->field('User.uid,avatar,nickname,is_promoter,pay_count,pay_price,spread_count,User.create_time')->page($page, $limit)->select();
- return compact('list', 'count','where');
- }
- /**
- * @param $uid
- * @param $page
- * @param $limit
- * @param array $where
- * @return array
- * @throws DataNotFoundException
- * @throws DbException
- * @throws ModelNotFoundException
- * @author xaboy
- * @day 2020/6/26
- */
- public function subOrder($uid, $page, $limit, array $where = [])
- {
- if (isset($where['level'])) {
- if (!$where['level']) {
- $ids = $this->dao->getSubIds($uid);
- $subIds = $this->dao->getSubAllIds($ids);
- } else if ($where['level'] == 2) {
- $ids = $this->dao->getSubIds($uid);
- $subIds = $this->dao->getSubAllIds($ids);
- $ids = [];
- } else {
- $ids = $this->dao->getSubIds($uid);
- $subIds = [];
- }
- } else {
- $ids = $this->dao->getSubIds($uid);
- $subIds = $this->dao->getSubAllIds($ids);
- }
- $all = array_merge($ids, $subIds);
- if (!count($all)) return ['count' => 0, 'list' => []];
- $query = app()->make(StoreOrderRepository::class)->usersOrderQuery($where, $all);
- $count = $query->count();
- $list = $query->page($page, $limit)->field('uid,order_sn,pay_time,extension_one,extension_two')->with(['user' => function ($query) {
- $query->field('avatar,nickname,uid');
- }])->select()->toArray();
- foreach ($list as $k => $item) {
- $list[$k]['brokerage'] = in_array($item['uid'], $ids) ? $item['extension_one'] : $item['extension_two'];
- unset($list[$k]['extension_one'], $list[$k]['extension_two']);
- }
- return compact('count', 'list');
- }
- /**
- * @param User $user
- * @return User
- * @throws DataNotFoundException
- * @throws DbException
- * @throws ModelNotFoundException
- * @author xaboy
- * @day 2020/7/2
- */
- public function mainUser(User $user): User
- {
- if (!$user->main_uid || $user->uid == $user->main_uid) return $user;
- $switchUser = $this->dao->get($user->main_uid);
- if (!$switchUser) return $user;
- if ($user->wechat_user_id && !$switchUser->wechat_user_id) {
- $switchUser->wechat_user_id = $user->wechat_user_id;
- $switchUser->save();
- }
- return $switchUser;
- }
- public function switchUser(User $user, $uid)
- {
- if ($user->uid == $uid || !$this->dao->existsWhere(['uid' => $uid, 'phone' => $user->phone]))
- throw new ValidateException('操作失败');
- $this->dao->update($user->uid, ['main_uid' => $uid]);
- $switchUser = $this->dao->get($uid);
- return $switchUser;
- }
- public function returnToken($user, $tokenInfo)
- {
- $user = $user->hidden(['label_id', 'group_id', 'main_uid', 'pwd', 'addres', 'card_id', 'last_time', 'last_ip', 'create_time', 'mark', 'status', 'spread_uid', 'spread_time', 'real_name', 'birthday', 'brokerage_price'])->toArray();
- return [
- 'token' => $tokenInfo['token'],
- 'exp' => $tokenInfo['out'],
- 'user' => $user
- ];
- }
- public function switchBrokerage(User $user, $brokerage)
- {
- $user->now_money = bcadd($user->now_money, $brokerage, 2);
- $user->brokerage_price = bcsub($user->brokerage_price, $brokerage, 2);
- Db::transaction(function () use ($brokerage, $user) {
- $user->save();
- app()->make(UserBillRepository::class)->incBill($user->uid, 'now_money', 'brokerage', [
- 'link_id' => 0,
- 'status' => 1,
- 'title' => '佣金转入余额',
- 'number' => $brokerage,
- 'mark' => '成功转入余额' . floatval($brokerage) . '元',
- 'balance' => $user->now_money
- ]);
- app()->make(UserBillRepository::class)->decBill($user->uid, 'brokerage', 'now_money', [
- 'link_id' => 0,
- 'status' => 1,
- 'title' => '佣金转入余额',
- 'number' => $brokerage,
- 'mark' => '成功转入余额' . floatval($brokerage) . '元',
- 'balance' => $user->brokerage_price
- ]);
- });
- }
- /**
- * 签到
- * @param $member_id
- * @throws DataNotFoundException
- * @throws DbException
- * @throws ModelNotFoundException
- */
- public function sub_signin($member_id){
- $member_info = Db::name('user')->where( array('uid' => $member_id) )->find();
- $config =systemConfig([
- 'isopen_signinreward',
- 'signinreward_day1_score',
- 'signinreward_day2_score',
- 'signinreward_day3_score',
- 'signinreward_day4_score',
- 'signinreward_day5_score',
- 'signinreward_day6_score',
- 'signinreward_day7_score',
- ]);
- //是否开启签到奖励
- $isopen_signinreward = empty($config['isopen_signinreward']) ? 0 : $config['isopen_signinreward'];
- if( $isopen_signinreward != 1 )
- {
- return array('code' => 1,'msg' => '签到奖励功能未开启');
- }
- //连续7天签到奖励
- $signinreward_day1_score = empty($config['signinreward_day1_score']) ? 0 : $config['signinreward_day1_score'];
- $signinreward_day2_score = empty($config['signinreward_day2_score']) ? 0 : $config['signinreward_day2_score'];
- $signinreward_day3_score = empty($config['signinreward_day3_score']) ? 0 : $config['signinreward_day3_score'];
- $signinreward_day4_score = empty($config['signinreward_day4_score']) ? 0 : $config['signinreward_day4_score'];
- $signinreward_day5_score = empty($config['signinreward_day5_score']) ? 0 : $config['signinreward_day5_score'];
- $signinreward_day6_score = empty($config['signinreward_day6_score']) ? 0 : $config['signinreward_day6_score'];
- $signinreward_day7_score = empty($config['signinreward_day7_score']) ? 0 : $config['signinreward_day7_score'];
- //准备数据
- $result = array();
- $result['signinreward_day1_score'] = $signinreward_day1_score;
- $result['signinreward_day2_score'] = $signinreward_day2_score;
- $result['signinreward_day3_score'] = $signinreward_day3_score;
- $result['signinreward_day4_score'] = $signinreward_day4_score;
- $result['signinreward_day5_score'] = $signinreward_day5_score;
- $result['signinreward_day6_score'] = $signinreward_day6_score;
- $result['signinreward_day7_score'] = $signinreward_day7_score;
- $today_signintime = time();
- $today_signin_info = Db::name('user_signinreward_record')->where( array('member_id' =>$member_id) )->whereDay('signin_time')->find();
- if( !empty($today_signin_info) )
- {
- return array('code' => 1,'msg' => '今天已经签到过了');
- }else{
- //查询昨天是否已经签到了
- $yes_signintime = strtotime( date('Y-m-d'). ' 00:00:00' ) - 86400;
- $yes_signin_info = Db::name('user_signinreward_record')->where( array('member_id' =>$member_id, 'signin_time' => $yes_signintime ) )->find();
- $has_qian = 1;
- if( !empty($yes_signin_info) )
- {
- $has_qian = $yes_signin_info['continuity_day'] +1;
- $has_qian = $has_qian > 7 ? 7 : $has_qian;
- }
- $get_score = $result["signinreward_day".$has_qian."_score"];
- $ins_data = array();
- $ins_data['member_id'] = $member_id;
- $ins_data['continuity_day'] = $has_qian;
- $ins_data['reward_socre'] = $get_score;
- $ins_data['signin_time'] = $today_signintime;
- $ins_data['addtime'] = time();
- $member_info = Db::name('user')->where( array('uid' => $member_id) )->find();
- $score = $member_info['now_score'];
- Db::name('user_signinreward_record')->insert($ins_data);
- $now_score=$score+$get_score;
- app()->make(UserBillRepository::class)->incBill($member_id, 'now_money', 'recharge', [
- 'link_id' => 1,
- 'status' => 1,
- 'title' => '签到积分',
- 'number' => $get_score,
- 'mark' => '连续签到'.$has_qian.'天赠送',
- 'balance' =>$now_score
- ]);
- Db::name('user')->where( array('uid' => $member_id) )->update(['now_score'=>$now_score]);
- // Db::name('log')->insert(['data'=>Db::name('user')->getLastSql(),'time'=>date('Y-m-d H:i:s',time())]);
- return array('code' =>0, 'now_score' => $score, 'continuity_day' => $has_qian,'reward_socre' => $get_score );
- }
- }
- public function get_signin($member_id,$where=[]){
- if ($where){
- $today_signin_info = Db::name('user_signinreward_record')->where( array('member_id' =>$member_id))->whereTime('signin_time', 'between', [$where['data1'], $where['data2']])->find();
- $show_day_arr= Db::name('user_signinreward_record')->where( array('member_id' =>$member_id))->whereTime('signin_time', 'between', [$where['data1'], $where['data2']])->column('signin_time');
- }else{
- $today_signin_info = Db::name('user_signinreward_record')->where( array('member_id' =>$member_id))->whereTime('signin_time',"today")->find();
- $show_day_arr= Db::name('user_signinreward_record')->where( array('member_id' =>$member_id))->whereTime('signin_time',"month")->column('signin_time');
- }
- $score= Db::name('user_signinreward_record')->where( array('member_id' =>$member_id) )->count('reward_socre');
- $leiji= Db::name('user_signinreward_record')->where( array('member_id' =>$member_id) )->sum('reward_socre');
- foreach ($show_day_arr as &$v){
- $v=date("Y-m-d",$v);
- }
- $result['score'] = $score;
- $result['today_is_signin'] = $today_signin_info?1:0;
- $result['leiji'] = $leiji;
- $result['show_day_arr'] = $show_day_arr;
- return $result;
- }
- public function add_cer($data=[],$member_id)
- {
- $renzeng=Db::name("user_certification")->where("uid",$member_id)->find();
- if ($renzeng){
- $res = Db::name('user_certification')->where("uid",$member_id)->update($data);
- }else{
- $res = Db::name('user_certification')->insert($data);
- }
- if($res){
- return [
- 'user_name' => $data['user_name'],
- 'age' => $this->getAgeByID($data['user_card']),
- 'user_card' => preg_replace('/(\d{6})\d{8}(\d{4})/', '$1****$2', $data['user_card']),
- ];
- }
- else{
- return false;
- }
- }
- public function get_cer($data=[])
- {
- $res = Db::name('user_certification')->where($data)->find();
- //计算年龄
- $res['age'] = $this->getAgeByID($res['user_card']);
- if($res){
- return $res;
- }
- else{
- return false;
- }
- }
- public function getAgeByID($id){
- //过了这年的生日才算多了1周岁
- if(empty($id)) return '';
- $date=strtotime(substr($id,6,8));
- //获得出生年月日的时间戳
- $today=strtotime('today');
- //获得今日的时间戳
- $diff=floor(($today-$date)/86400/365);
- //得到两个日期相差的大体年数
- //strtotime加上这个年数后得到那日的时间戳后与今日的时间戳相比
- $age=strtotime(substr($id,6,8).' +'.$diff.'years')>$today?($diff+1):$diff;
- return $age;
- }
- /**
- * @param $data
- *
- */
- public function addagent($user){
- if ($user){
- $data=[
- "identity"=>5,
- "status"=>1,
- "add_time"=>time(),
- "update_time"=>time(),
- "user_id"=>$user->uid,
- "name"=>"推广员",
- "pay_status"=>1,
- "price"=>0,
- "agent_sn"=>time(),
- ];
- Db::name("user_agent")->insert($data);
- }
- }
- /*
- * 申请代理
- @cabbage
- */
- public function agent($data){
- $user = Db::name("user")->where(['uid'=>$data['user_id']])->field("identity,account,uid")->find();
- //判断所申请的区域下是否有代理
- if($data['identity'] == 1){
- if(Db::name("user_street")->where("street_id",$data['street_id'])->value("uid")){
- return ['code'=>400,'msg'=>'该区域下已有代理'];
- }
- }elseif($data['identity'] == 2){
- if(Db::name("user_area")->where("area_id",$data['area_id'])->value("uid")){
- return ['code'=>400,'msg'=>'该区域下已有代理'];
- }
- }elseif($data['identity'] == 3){
- if(Db::name("user_city")->where("city_id",$data['city_id'])->value("uid")){
- return ['code'=>400,'msg'=>'该区域下已有代理'];
- }
- }
- //判断是不是商户
- // if($user['identity']==4){
- // return ['code'=>'400','msg'=>"不符合申请代理的条件"];
- // }
- //判断用户是否是其他代理身份
- // if(in_array($user['identity'],[1,2,3,5])){
- // return ['code'=>'400','msg'=>"用户已是推广身份"];
- // }
- if($user['identity']==$data['identity']){
- return ['code'=>'400','msg'=>"用户已是该身份,无需申请"];
- }
- if($data['spread_account'] == $user['account']){
- return ['code'=>'400','msg'=>"推荐人不能是自己"];
- }
- $real = Db::name("user_certification")->where(["uid"=>$data['user_id'],'status'=>1])->find();
- //判断是否实名认证
- if(!$real){
- return ['code'=>'400','msg'=>"请先实名认证"];
- }
- if($user){
- if($data['identity'] == $user['identity']){
- return ['code'=>'400','msg'=>"已经是该级别代理"];
- }
- if(!in_array($user['identity'],[4,5]) && $data['identity'] < $user['identity']){
- return ['code'=>'400','msg'=>"不能申请低于现在级别的代理"];
- }
- }
- $is_apply= Db::name("user_agent")->where(["user_id"=>$data["user_id"],'status'=>[0,2]])->find();
- if ($is_apply){
- if($is_apply['status'] == 0){
- return ['code'=>'400','msg'=>"您有审核中的代理申清"];
- }
- if($is_apply['status'] == 2) {
- $data['status']= 0;//恢复申请中状态
- $res= Db::name("user_agent")->where("id",$is_apply['id'])->update($data);
- if($res){
- return true;
- }
- }
- }
- $res= Db::name("user_agent")->insert($data);
- if($res){
- return true;
- }
- }
- public function isAgent($uid){
- $res = Db::name("user_agent")
- ->where(["user_id"=>$uid])
- ->whereIn('status',[0,1,2])
- ->whereIn('identity',[1,2,3,6])
- ->order("add_time desc")
- ->find();
- if(!$res){
- return json_encode([]);
- }
- $res['province_name'] = Db::name("user_province")->where(['province_id'=>$res['province_id']])->value("province_name");
- $res['city_name'] = Db::name("user_city")->where(['city_id'=>$res['city_id']])->value("city_name");
- $res['area_name'] = Db::name("user_area")->where(['area_id'=>$res['area_id']])->value("area_name");
- $res['street_name'] = Db::name("user_street")->where(['street_id'=>$res['street_id']])->value("street_name");
- switch ($res['identity']){
- case '1':
- $res['name'] = '镇级服务商';
- break;
- case '2':
- $res['name'] = '县级服务商';
- break;
- case '3':
- $res['name'] = '市级服务商';
- break;
- case '6':
- $res['name'] = '渠道商';
- }
- return $res;
- }
- public function getAgentPayDetail($where=[]){
- $res= Db::name("user_agent")->where($where)->find();
- return $res;
- }
- public function get_agent_info($member_id){
- $user=Db::name("user")->where("uid",$member_id)->find();
- $data=[
- "nickname"=>$user["nickname"],
- "avatar"=>$user["avatar"],
- "is_promoter"=>$user["is_promoter"],
- "identity"=>$user["identity"],
- "brokerage_price"=>set_price_rtrim($user["brokerage_price"]),
- "uid"=>$member_id,
- ];
- $data["yesterday"]=(string)Db::name("user_bill")->whereDay('create_time', 'yesterday')->where(["uid"=>$member_id,"type"=>"commission","status"=>1])->where("commission_type","<>",5)->sum("number");
- $data["cumulative"]=(string)Db::name("user_bill")->where(["uid"=>$member_id,"type"=>"commission","status"=>1,"is_red_brokerage"=>0])->where("commission_type","<>",5)->sum("number");
- $data["extract"]=(string)Db::name("user_extract")->where(["uid"=>$member_id,"status"=>1])->sum("extract_price");
- return $data;
- }
- /*
- * 全民营销->推广统计
- */
- public function get_extension_info($member_id,$search,$where=[]){
- $data=[];
- $data["count_zong"]=Db::name("user_identity_log")->where(["uid"=>$member_id])->count();
- $data["town"]=Db::name("user_identity_log")->where(["uid"=>$member_id,'identity'=>1])->whereNotIn("identity","0")->count();
- $data["county"]= Db::name("user_identity_log")->where(["uid"=>$member_id,'identity'=>2])->whereNotIn("identity","0")->count();
- $data["city"]= Db::name("user_identity_log")->where(["uid"=>$member_id,'identity'=>3])->whereNotIn("identity","0")->count();
- $data["shop"]=Db::name("user_identity_log")->where(["uid"=>$member_id,'identity'=>4])->whereNotIn("identity","0")->count();
- $data["tuiguang"]=Db::name("user_identity_log")->where(["uid"=>$member_id])->whereIn('identity','5,0')->count();
- $query =Db::name("user_identity_log")->alias("a")
- ->join('user s',"a.link_id=s.uid")
- ->where(["a.uid"=>$member_id])
- ->field("s.nickname,a.create_time,a.identity,s.phone");
- if(isset($where['identity']) && $where['identity'] != ''){
- $query = $query->where(['a.identity'=>$where['identity']]);
- }
- if(isset($search) && $search !=''){
- $query =$query->whereLike('s.account','%'.$search.'%');
- }
- $list = $query->select();
- $data["list"]=$list;
- return $data;
- }
- public function get_profit_info($member_id,$where){
- // $data["count_yj"]=Db::name("user")->where(["type"=>"commission"])->sum("number");
- // $data["dlfee"]=Db::name("user")->where(["type"=>"commission","commission_type"=>1])->sum("number");
- // $data["xiaofee"]=Db::name("user")->where(["type"=>"commission","commission_type"=>2])->sum("number");;
- // $data["county"] =Db::name("user")->where(["type"=>"commission","commission_type"=>1])->sum("number");;
- // $data["town"]==Db::name("user")->where(["type"=>"commission","commission_type"=>1])->sum("number");;
- $query = Db::name("user_bill")->where(["type"=>"commission",'uid'=>$member_id])
- ->field("type,number,status,commission_type,create_time,uid,title,order_sn");
- $order = "create_time desc";
- if($where['date_on'] == 1){
- $order = "create_time desc";
- }elseif($where['date_off'] == 1){
- $order = "create_time asc";
- }
- if(isset($where['commission_type']) && $where['commission_type'] !=''){
- $query = $query->where(['commission_type'=>$where['commission_type']]);
- }else{
- $query = $query ->whereIn("commission_type",[1,2,3,4,7,8,9,10]);
- }
- if(isset($where['order']) && in_array($where['order'],["today","yesterday","week","month","year"])){
- $query = $query->whereTime("create_time",$where['order']);
- }
- $list= $query->order($order)->select()->toArray();
- $dangqian_yj=Db::name("user")->where("uid",$member_id)->value("brokerage_price");
- $dlfee=0;
- $xiaofei=0;
- $tuiguang=0;
- $xiaqu=0;
- $weijiesuan=0;
- $qudao=0;
- foreach ($list as &$v){
- // $count_yj=$v["number"]+$count_yj;
- if ($v["status"]==0){
- $v["title"]="【预估】".$v["title"].",单号:".$v["order_sn"];
- $weijiesuan+=$v['number'];
- }elseif($v["status"]==-1){
- $v["title"]="【失效】".$v["title"].",单号:".$v["order_sn"];
- }else{
- if ($v["commission_type"]==1){
- $dlfee+=$v["number"];
- }
- if ($v["commission_type"]==2){
- $xiaofei+=$v["number"];
- }
- if ($v["commission_type"]==3){
- $tuiguang+=$v["number"];
- }
- if ($v["commission_type"]==4){
- $xiaqu+=$v["number"];
- }
- if ($v["commission_type"]==6||$v["commission_type"]==7){
- $tuiguang+=$v["number"];
- }
- if ($v["commission_type"]==9){
- $qudao+=$v["number"];
- }
- if ($v["commission_type"]==10){
- $tuiguang+=$v["number"];
- }
- }
- }
- $data["count_yj"]=round($dangqian_yj,2);//当前佣金
- $data["dlfee"]=round($dlfee,2); //代理非
- $data["xiaofei"]=round($xiaofei,2); //消费佣金
- $data["tuiguang"]= round($tuiguang,2); //推广佣金
- $data["xiaqu"]=round($xiaqu,2); //辖区佣金
- $data["weijiesuan"]=round($weijiesuan,2);//未结束佣金
- $data["qudao"]=round($qudao,2);//渠道
- $data["list"]=$list;
- return $data;
- }
- /*
- * 越攒越多统计
- * */
- public function get_com_all($member_id,$where){
- $query = Db::name("user_bill")->where(["type"=>"commission",'uid'=>$member_id])
- ->field("type,number,status,commission_type,create_time,uid,title,order_sn,type_shop");
- $order = "create_time desc";
- if(isset($where['commission_type']) && $where['commission_type'] !=''){
- $query = $query->where(['commission_type'=>$where['commission_type']]);
- }else{
- $query = $query ->whereIn("commission_type",[1,2,3,4,7,8,9,10]);
- }
- if(isset($where['order']) && in_array($where['order'],["today","yesterday","week","month","year"])){
- $query = $query->whereTime("create_time",$where['order']);
- }
- $query = $query->where(['status'=>1]);
- $list= $query->order($order)->select()->toArray();
- $dangqian_yj=Db::name("user")->where("uid",$member_id)->value("brokerage_price");
- $dlfee=0;
- $xiaofei=0;
- $tuiguang=0;
- $kuadian=0;
- $xiaqu=0;
- $weijiesuan=0;
- $ptjl=0;
- $qudao=0;
- foreach ($list as &$v){
- // $count_yj=$v["number"]+$count_yj;
- if ($v["commission_type"]==1){
- $dlfee+=$v["number"];
- }
- if ($v["commission_type"]==2){
- $xiaofei+=$v["number"];
- }
- if ($v["commission_type"]==3){
- $tuiguang+=$v["number"];
- }
- if ($v["commission_type"]==4){
- $xiaqu+=$v["number"];
- $v['title'] = '辖区获取佣金';
- }
- if ($v["commission_type"]==7){
- $kuadian+=$v["number"];
- $v['title'] = '跨店获取佣金';
- }
- if ($v["commission_type"]==8){
- $ptjl+=$v["number"];
- $v['title'] = '平台奖励佣金';
- }
- if ($v["commission_type"]==9){
- $qudao+=$v["number"];
- $v['title'] = '渠道商奖励佣金';
- }
- if ($v["commission_type"]==10){
- $tuiguang+=$v["number"];
- $v['title'] = '推荐商户奖励佣金';
- }
- // if ($v['type_shop'] >0){
- // $qudao+=$v['number'];
- // $v['title'] = '第三方订单获取佣金';
- // }
- }
- $data["count_yj"]=round($dangqian_yj,2);//当前佣金
- $data["dlfee"]=round($dlfee,2); //代理非
- $data["xiaofei"]=round($xiaofei,2); //消费佣金
- $data["tuiguang"]= round($tuiguang,2); //推广佣金
- $data["xiaqu"]=round($xiaqu,2); //辖区佣金
- $data["weijiesuan"]=round($weijiesuan,2);//未结束佣金
- $data["kuadian"]=round($kuadian,2); //跨店
- $data["ptjl"]=round($ptjl,2); //平台奖励佣金
- $data["qudao"]=round($qudao,2); //渠道
- return $data;
- }
- /*
- * 越攒越多列表
- * */
- public function get_com_list($member_id,$where){
- $query = Db::name("user_bill")->where(["type"=>"commission",'uid'=>$member_id])
- ->field("type,number,status,commission_type,create_time,uid,title,order_sn,type_shop");
- $order = "create_time desc";
- if(isset($where['commission_type']) && $where['commission_type'] !=''){
- $query = $query->where(['commission_type'=>$where['commission_type']]);
- }else{
- $query = $query ->whereIn("commission_type",[1,2,3,4,7,8,9,10]);
- }
- if(isset($where['order']) && in_array($where['order'],["today","yesterday","week","month","year"])){
- $query = $query->whereTime("create_time",$where['order']);
- }
- $page = $where['page'] ?? 1;
- $limit = $where['limit'] ?? 10;
- $query = $query->where(['status'=>1]);
- $list= $query->page($page,$limit)->order($order)->select()->toArray();
- $data["list"]=$list;
- return $data;
- }
- /**
- * 获取推广列表
- */
- public function get_tuiguang_list($member_id,$where = []){
- $query = Db::name("user_bill")
- ->alias("ul")
- ->where(["ul.type"=>"commission",'ul.uid'=>$member_id])
- ->field("ul.mark,ul.bill_id,ul.type,ul.number,ul.status,ul.create_time,ul.uid,ul.order_sn,ul.create_time,ul.link_id,ul.type_shop,ul.commission_type,ul.source");
- if(isset($where['type']) && in_array($where['type'],[0,1])){
- $query = $query->where(['ul.source'=>$where['type']]);
- }
- if(isset($where['order']) && in_array($where['order'],["today","yesterday","week","month","year"])){
- $query = $query->whereTime("create_time",$where['order']);
- }
- $page = $where['page'] ?? 1;
- $limit = $where['limit'] ?? 10;
- $query = $query ->whereIn("commission_type",[1,2,3,4,7,8,9,10]);
- $query = $query ->where("status",'>=',0);
- //不显示红积分的
- $query = $query ->where("is_red_brokerage",'=',0);
- $list= $query->order("create_time desc")->page($page,$limit)->select()->toArray();
- foreach ($list as &$v){
- // $v["create_time"]=date("Y-m-d", $v["create_time"]);
- //0平台1多多进宝2唯品会3苏宁易购4网易考拉5淘宝客6京东联盟7饿了么
- if($v['type_shop'] == 0){
- if($v['source'] == 0){
- if($v['commission_type'] == 9){
- $this -> getContent('channel_order',$v['order_sn'],'储蓄保',$v['status'],$v['commission_type'],$v);
- }elseif($v['commission_type'] == 10){
- $this -> getContent('merchant_annual_cost_order',$v['order_sn'],'储蓄保',$v['status'],$v['commission_type'],$v);
- }else{
- $this -> getContent('store_order',$v['order_sn'],'储蓄保',$v['status'],$v['commission_type'],$v,$v['create_time']);
- }
- }else{
- $uid=Db::name("store_order")->where("order_sn",$v["order_sn"])->value("uid");
- $v["nickname"]=$this -> getUserNickname($uid);
- $v['content'] = '用户'.$v['nickname'].'到店消费,帮您攒金';
- $v['xiadan'] = $v['create_time'] ?? '';
- $v['jiesuan'] = $v['create_time'];
- }
- }elseif ($v['type_shop'] == '1'){
- $this -> getContent('order_pdd',$v['order_sn'],'拼多多',$v['status'],$v['commission_type'],$v);
- }elseif ($v['type_shop'] == '2'){
- $this -> getContent('order_vip',$v['order_sn'],'唯品会',$v['status'],$v['commission_type'],$v);
- }elseif ($v['type_shop'] == '3'){
- $this -> getContent('order_su',$v['order_sn'],'苏宁易购',$v['status'],$v['commission_type'],$v);
- }
- elseif ($v['type_shop'] == '4'){
- // $uid = Db::name('order_jd')->where("order_sn",$v["order_sn"])->value("uid");
- // $v["nickname"]=$this -> getUserNickname($uid);
- $v["nickname"]='';
- $v['content'] = $v['nickname'].'在网易考拉消费,帮您攒金';
- $v['xiadan'] = '';
- $v['jiesuan'] = '';
- }elseif ($v['type_shop'] == '5'){
- $this -> getContent('order_tb',$v['order_sn'],'淘宝',$v['status'],$v['commission_type'],$v);
- }elseif ($v['type_shop'] == '6'){
- $this -> getContent('order_jd',$v['order_sn'],'京东',$v['status'],$v['commission_type'],$v);
- }elseif ($v['type_shop'] == '7'){
- $this -> getContent('order_tb',$v['order_sn'],'饿了么',$v['status'],$v['commission_type'],$v);
- }
- if($v['commission_type'] == 7){
- $v['mark'] = '【跨店】'.$v['mark'];
- }
- $v['number'] =set_price_rtrim($v['number']);
- }
- return $list;
- }
- public function getUserNickname($uid){
- return Db::name("user")->where("uid", $uid)->value("nickname");
- }
- public function getContent($table,$order_sn,$title,$status,$commission_type,&$v,$create_time=null){
- $yugu = '';
- if($status == 0){
- $yugu = "【预估】";
- if($commission_type == 7){
- $yugu = "【跨店预估】";
- }
- }
- switch ($table){
- case 'store_order':
- $res = Db::name($table)->where("order_sn",$order_sn)->field('uid,create_time,pay_time')->find();
- $v["nickname"]=$this -> getUserNickname($res['uid']);
- $v['content'] = $yugu.$v['nickname'].'在'.$title.'消费,帮您攒金';
- break;
- case 'channel_order':
- $res = Db::name($table)->where("order_no",$order_sn)->field('uid,create_time,pay_time')->find();
- $v["nickname"]=$this -> getUserNickname($res['uid']);
- $v['content'] = $v['nickname'].'成为渠道商,帮您攒金';
- $res['bill_end_time'] = strtotime($res['create_time']);
- break;
- case 'merchant_annual_cost_order':
- $res = Db::name($table)->where("order_no",$order_sn)->field('uid,create_time,pay_time')->find();
- $v["nickname"]=$this -> getUserNickname($res['uid']);
- $v['content'] = $v['nickname'].'成为商户,帮您攒金';
- $res['bill_end_time'] = strtotime($res['create_time']);
- break;
- default:
- $res = Db::name($table)->where("order_sn",$order_sn)->field('uid,create_time,bill_end_time,pay_time')->find();
- $v["nickname"]=$this -> getUserNickname($res['uid']);
- $v['content'] = $yugu.$v['nickname'].'在'.$title.'消费,帮您攒金';
- }
- // $v['xiadan'] = $res['create_time'] ?? $create_time;
- $v['xiadan'] = isset($res['pay_time'])?$res['pay_time']:$create_time;
- $v['jiesuan'] = $v['xiadan'];
- // if (empty($res['bill_end_time']) && empty($res['create_time'])){
- // $v['jiesuan'] = $create_time;
- // }else{
- // $v['jiesuan'] = date('Y-m-d H:i:s',$res['bill_end_time']??strtotime("+10 day", strtotime($res['create_time'])));
- // }
- }
- /**
- * 获取订单数
- */
- public function get_tuiguang_order($member_id){
- $where=["ul.type"=>"commission","ul.status"=>1,'ul.uid'=>$member_id];
- $list=Db::name("user_bill")
- ->alias("ul")
- // ->join("user u","u.uid=ul.uid")
- ->where("commission_type","<>",5)
- ->where($where)
- ->field("ul.mark,ul.bill_id,ul.type,ul.number,ul.status,ul.create_time,ul.uid,ul.order_sn,ul.create_time,ul.link_id")
- ->select();
- $num=0;
- $count=0;
- foreach ($list as &$v){
- $num++;
- // $v["create_time"]=date("Y-m-d", $v["create_time"]);
- $uid=Db::name("store_order")->where("order_sn",$v["order_sn"])->value("uid");
- $v["nickname"]=Db::name("user")->where("uid", $uid)->value("nickname");
- $count+=$v["number"];
- }
- return ["num"=>$num,"count"=>round($count,2),"list"=>$list];
- }
- public function get_yanglao($member_id){
-
- $data = Db::name("user")
- ->where("uid",$member_id)
- ->field("wechat_user_id,card_id,ali_user_id,annuity_frozen,annuity_num,annuity,create_time,birthday,birthday60,card_number,annuity_yiqu,pay_price")
- ->find();
- // $data['annuity'] = 0;
- $certification = Db::name("user_certification")->where("uid",$member_id)->find();
- $data['can_withdraw'] = 0;
- if (!$certification || $certification["status"] !=1 || !$certification["user_card"]){
- $data["birthday60"] = "未实名认证";
- $data['is_certification'] = 0;
- } else {
- // try {
- // $checkAmount = $this->checkAmount($certification);
- // if ($checkAmount['code'] == 0) {
- // $data['annuity'] = $checkAmount['extendData']['amount'];
- // }
- // } catch (\Throwable $e) {
- // Log::info('getyanglaojin' . $e->getMessage());
- // }
- $data['is_certification'] = 1;
- $birth_data = substr($certification["user_card"], 6, 8);
- // $birth = strtotime(substr($certification["user_card"], 6, 8));
- $old_age = $this->getSex($certification["user_card"])?60:55;
- // $age = $this->howOld($birth);
- $age=$this->calculateAge($birth_data);
- if ($age < $old_age) {
- // $yes = $old_age - $age;
- // $data["birthday60"] = date("Y-" . substr($birth_data, 4, 2) . '-' . substr($birth_data, 6, 2), strtotime("+" . $yes . " year"));
- }
- if ($age == $old_age) {
- $data['can_withdraw'] = 1;
- // $data["birthday60"] = date("Y-m-d", $birth);
- }
- if ($age > $old_age) {
- $data['can_withdraw'] = 1;
- // $yes = $age - $old_age;
- // $data["birthday60"] = date("Y-" . substr($birth_data, 4, 2) . '-' . substr($birth_data, 6, 2), strtotime("-" . $yes . " year"));
- }
- //收益余额
- $data['annuity_num'] = 123;
- $data['annuity_yiqu'] = 123;
- $data["birthday60"] = $this->getFutureBirthday($birth_data,$old_age);
- }
- $order_merchant_price= OrderMerchant::getInstance()->where('paid', 1)
- ->where(function ($query) use ($data) {
- $query->where('pay_user_id', $data['wechat_user_id'])
- ->whereOr('pay_user_id', $data['ali_user_id']);
- })
- ->sum('money');
- //加上线下消费的
- $data['pay_price'] = bcadd($data['pay_price'],$order_merchant_price,2);
- $data["yinghang"] = "中信公证处消费养老金账户";
- // $data["yinghang"]='https://app.bjtdba.com/uploads/def/20201021/8cb66944101287b8ac9c9b9fb1b13a79.png';
- $data["add_up"] = 0.00;
-
- return $data;
- }
- function calculateAge($birthDate) {
- $today = new \DateTime();
- $diff = $today->diff(new \DateTime($birthDate));
- return $diff->y;
- }
- function getFutureBirthday($birthDate, $years) {
- $date = new \DateTime($birthDate);
- $date->modify("+$years years");
- return $date->format('Y-m-d');
- }
- public function getSex($cid){
- //根据身份证号,自动返回性别
- $sexint = (int)substr($cid,16,1);
- return $sexint % 2 === 0 ? false : true;
- }
- /**
- * 根据时间戳计算年龄
- * @param $birth
- * @return mixed
- */
- public function howOld($birth) {
- list($birthYear, $birthMonth, $birthDay) = explode('-', date('Y-m-d', $birth));
- list($currentYear, $currentMonth, $currentDay) = explode('-', date('Y-m-d'));
- $age = $currentYear - $birthYear - 1;
- if($currentMonth > $birthMonth || $currentMonth == $birthMonth && $currentDay >= $birthDay)
- $age++;
- return $age;
- }
- public function yanglaolog($where,$page=1, $limit=10,$month=''){
- $where1 = [];
- if(!empty($where)){
- foreach($where as $key => $value){
- $where1['a.'.$key] = $value;
- }
- }
- $query=Db::name("user_bill")
- ->alias('a')
- ->join('Merchant b', 'a.mer_id = b.mer_id','left')
- ->field('a.*,b.mer_name,b.mer_avatar')
- ->where($where1)
- ->when($month!='',function ($q) use ($month){
- $q->whereLike('a.create_time',$month.'%');
- });
- $query -> where('a.status','<>','-1');
- $query_sql1 = clone $query;
- $query_sql2 = clone $query;
- $query_sql3 = clone $query;
- $count = $query->count();
- $list = $query->page($page,$limit)->order("a.bill_id desc")->select()
- ->each(function($item){
- if($item['source'] == 0 && $item['type_shop'] == 0){
- $item['product'] = json_decode(Db::name("store_order")
- -> alias('a')
- -> join('store_order_product b','a.order_id = b.order_id','left')
- -> where(["a.order_sn"=>$item['order_sn']])
- -> value('b.cart_info'),true);
- if(empty($item['product'])){
- $item['product']=[
- 'product'=>[
- 'image'=>'http://app.bjtdba.com/uploads/def/20210326/e91a34629fefb65170071c2d45a623ac.jpg',
- 'store_name'=>'商家年费'
- ]
- ];
- }
- }
- return $item;
- });
- $yugu=$query_sql1->sum('number');
- $yijiesuan=$query_sql1->where('a.status',1)->sum('number');
- $weijiesuan=$yugu-$yijiesuan;
- return compact('count','list','yugu','yijiesuan','weijiesuan');
- }
- /*养老金详情*/
- public function yanglaoDetail($where=[],$field='*'){
- $query=Db::name("user_bill")->where($where)->field($field)->find();
- return $query;
- }
- /*提现记录 type 1佣金 2养老金*/
- public function withdrawal($where){
- $data=Db::name("user_extract")->where($where)->order('extract_id','desc')->select();
- if(!$data->isEmpty()){
- $data=$data->toArray();
- }
- foreach ($data as $k=>&$v){
- if($v['withdrawal_type']==2){
- // $name=Db::name('merchant')->where('mer_id',$v['mer_id'])->value('mer_name');
- $v['title']='佣金提现';
- }else if($v['withdrawal_type']==3){
- if($v['extract_type']==1){
- $tltle='微信';
- $v['title']='提现到'.$tltle;
- }else if($v['extract_type']==3){
- $tltle='银行卡';
- $v['title']='提现到'.$tltle;
- }else if($v['extract_type']==4){
- $v['title']='人工减少佣金';
- }
- }else{
- $v['title']='储蓄保-佣金提现';
- }
- if($v['bank_info']!=''){
- $bank_info=json_decode($v['bank_info'],true);
- }
- $v['extract_price']=set_price_rtrim($v['extract_price']);
- $v['bank_name']=isset($bank_info['bank_name'])?$bank_info['bank_name']:'';
- }
- return $data;
- }
- /*提现记录 type 1佣金 2养老金*/
- public function withdrawal_user($where){
- $data=Db::name("user_extract")->where($where)->where('mer_id is null')->order('extract_id','desc')->select();
- if(!$data->isEmpty()){
- $data=$data->toArray();
- }
- foreach ($data as $k=>&$v){
- if($v['withdrawal_type']==2){
- // $name=Db::name('merchant')->where('mer_id',$v['mer_id'])->value('mer_name');
- $v['title']='佣金提现';
- }else if($v['withdrawal_type']==3){
- if($v['extract_type']==1){
- $tltle='微信';
- $v['title']='提现到'.$tltle;
- }else if($v['extract_type']==3){
- $tltle='银行卡';
- $v['title']='提现到'.$tltle;
- }else if($v['extract_type']==4){
- $v['title']='人工减少佣金';
- }
- }else{
- $v['title']='储蓄保-佣金提现';
- }
- if($v['bank_info']!=''){
- $bank_info=json_decode($v['bank_info'],true);
- }
- $v['extract_price']=set_price_rtrim($v['extract_price']);
- $v['bank_name']=isset($bank_info['bank_name'])?$bank_info['bank_name']:'';
- }
- return $data;
- }
- /*
- * 提现详情
- *@author cabbage
- *@date 2020-10-31
- * */
- public function withdrawalDetail($id,$uid){
- $data= Db::name("user_extract")->where(["uid"=>$uid,'extract_id'=>$id,"type"=>2])->find();
- return $data;
- }
- /*
- * 修改用户推广人id
- *@author cabbage
- *@date 2020-10-31
- * */
- public function update_spread($uid,$spread_account){
- //推荐人信息
- $spread = Db::name("user")->where('account',$spread_account)->field("uid")->find();
- //被推荐人信息
- $identity=Db::name("user")->where('uid',$uid)->field("identity,spread_uid")->find();
- $user_identity_log=Db::name("user_identity_log")->where(["link_id"=>$uid])->find();
- if($spread){
- try{
- $data= Db::name("user")->where(["uid"=>$uid])->update(['spread_uid'=>$spread['uid']]);
- Db::name("merchant")->where(["uid"=>$uid])->update(['recommender'=>$spread['uid']]);
- if ($user_identity_log){
- Db::name("user_identity_log")->where(["id"=>$user_identity_log["id"]])->update(['uid'=>$spread['uid']]);
- }else{
- Db::name("user_identity_log")->insert(['uid'=>$spread['uid'],"identity"=>$identity["identity"],"create_time"=>date("Y-m-d H:i:s"),"link_id"=>$uid]);
- }
- Db::name("user")->where('account',$spread_account)->inc("spread_count",1)->update();
- if ($identity["spread_uid"]){
- Db::name("user")->where('uid',$identity["spread_uid"])->dec("spread_count")->update();
- }
- return $data;
- }catch (Exception $e) {
- Db::rollback();
- }
- }else{
- return false;
- }
- }
- /*获取协议列表*/
- public function getXieYi(){
- $data= Db::name("user_agreement")->where(["status"=>1])->select();
- return $data;
- }
- /*积分记录*/
- public function socreList($uid,$page,$limit){
- $data = Db::name("user_signinreward_record")
- ->where(['member_id'=>$uid])
- ->field("reward_socre,addtime")
- ->page($page,$limit)
- ->order("addtime desc")
- ->select()->toArray();
- foreach ($data as $k => $v) {
- $data[$k]['addtime'] = date("y-m-d H:i:s",$v['addtime']);
- $data[$k]['pm'] = 1 ;
- $data[$k]['mark'] = '签到获得' ;
- }
- $result['list'] = $data;
- $result['count'] = Db::name("user_signinreward_record")->where(['member_id'=>$uid])->count();
- $result['total_socre'] = Db::name("user_signinreward_record")->where(['member_id'=>$uid])->sum("reward_socre");
- $result['is_use'] = 0 ;
- $result['is_pass'] = 0 ;
- return $result;
- }
- /*修改用户信息*/
- public function updateUser($uid,$data,$data2=[]){
- $data = Db::name("user")->where(['uid'=>$uid])->update($data);
- if ($data2){
- $ck= Db::name("user_account")->where(["uid"=>$uid,"type"=>$data["type"]])->find();
- if ($ck){
- $data= Db::name("user_account")->where(["id"=>$ck["id"]])->update($data2);
- }else{
- $data= Db::name("user_account")->insert($data2);
- }
- }
- return $data;
- }
- /*获取用户信息*/
- public function getUser($uid,$data){
- $user = Db::name("user")->where(['uid' => $uid])->field($data)->find();
- $data = Db::name("user_account")->where(['uid' => $uid])->select()->toArray();
- $types = array_column($data, 'type');
- if (!in_array('1', $types) && $user['wechat_user_id']) {
- $data[] = ['id' => 0, 'avater' => '', 'nickname' => null, 'type' => 1, 'uid' => $uid];
- Db::name("user_account")->insert(['type' => 1, 'uid' => $uid]);
- }
- if (!in_array('2', $types) && $user['ali_user_id']) {
- $data[] = ['id' => 0, 'avater' => '', 'nickname' => null, 'type' => 2, 'uid' => $uid];
- Db::name("user_account")->insert(['type' => 2, 'uid' => $uid]);
- }
- return $data;
- }
- public function getAccount($uid)
- {
- $res=Db::name('user_extract_openid')->where('uid',$uid)->value('openid');
- if($res){
- $arr[]=array(
- 'id'=>'1',
- 'type'=>'1',
- 'uid'=>$uid,
- 'nickname'=>'',
- 'avater'=>'',
- );
- }
- $res = Db::name('user') -> where('uid',$uid) -> value('ali_user_id');
- if($res && $res != '0' && $res != ''){
- $arr[]=array(
- 'id'=>'2',
- 'type'=>'2',
- 'uid'=>$uid,
- 'nickname'=>'',
- 'avater'=>'',
- );
- }
- return isset($arr)?$arr:[];
- }
- /**
- * 支付宝授权登录
- * 文档:https://opendocs.alipay.com/open/218/105327
- */
- public function aliSign(){
- $aop = new AopClient;
- $aop->gatewayUrl = "https://openapi.alipay.com/gateway.do";
- $aop->appId = "2021001197654668";
- $aop->rsaPrivateKey = 'MIIEpAIBAAKCAQEAlGWxvrR9KGkheEK4kTrcKDvK3ovhwi+zc4zxa11DZgpyUk2Kr2RT08ZQPaQLm9jQFlzwzqVgbAL9DFBTRAaD4nEMHoR0ZfR9ueRirko16Kjkx8AOPVYdEIy68U01gln/N9Y0iq8YVxu4Yv8vorY7U8aSJUcAnkx9bPbhei8SZxVgC2KldextzyVh9t/tAk2WAxbLmvieF746lY1u0W6AfmBIvQWdjbw3wJUMxMYrlp501zHr7kecgcYhnOnYkO9ehpVSAYJHoDDAulBEkapiSGiP09aOe3jhsutFDIrxL4BoFyNtaAOCbh6sUa9mMNu67wRBXwitfK7wOdt1gzfmOwIDAQABAoIBAQCODzQyzfGqh8nkqGqrjN9JHMQ+e0ZpcOSnT1ulXiixPHroUxbahH7DEuuptqruTIYXgm18RVCi1dGMwjCTxHDoizQA2ufa2kypcfsNwjkNOvGYT0DScudr+mzTpwf8e08ZEtRFlw0EBqNjEct2RmFQ95zcVrY+1BaWA1kicIF7b7/Zto7x7xAnR10tfRE2bUePBzruugZRk+Z9LbcKSRDAb/JBEFKHzfiBIFyIcEj9covcNVFF8QCkraxugDxH0dxYheFz7sxvjLyo2OYW+Xs2Q95/kVZIGWdz2T4IIqdvqjWzCn+azMvpB7056ziFrit6E2JNQH+8DrWsHj2b3xnhAoGBAOFwF44Qce7c9zTnvzZZlqONuHrzhsSxvHEU2mf+FitpFFASOhJcPoK18M0ZsUX7EwVQLCKSoKcdk34Y3msM0E+aihRpwBQbR1isdnSnbTcBRRpmVHnX50qXjHabvY4lPJQssMKsf0ezitFQP1NA7oNWhJzEDTRNZxqlo4Y3JGf5AoGBAKiD4MKR24l9EJ+aMnPW50jIkNj/sWslYTZn5b7zyt3e1gj39Er5ePCgzqVmKt5SK/SnS1PxEcQurVuw2Gs4/9vAYc25QAAYhZCbgHRTUhv1+1xontLyIIXChQABJElAEkTj+bpB5ps/rwOVR3znMyS1135o4Q+DyP+SW7BZ/NTTAoGBANp+J3Y7HhGh+7489igZAFUYIDqaGH4+vSLkUSIFMztzpopMgBgXa0aITBCc3CG1TCQUJhKEBkyx76eBNuCOFL9ySm2qaM2T+rxIuq4pL0LmajFCCJHm3XaAF1VFcJx6HpKGFfM3+ExoCR0BJ77q6cBFdFXz9dBBTLKY4zpL628RAoGAUeARejen9PtA8mrXDJVjtmdMiUJij26P9wEwDUEiVf6I+76NgUgIzNE01gP33CEMnkgSP2yndyw+qogX/rCpD7o/StcxE1rWulXzaZF6GX/Aazuhv1hJGPRT7pafbL+moLYrhaWzR8b/X7xOCY/Dt5hqZU7L2t/q7tHLnrl6MGUCgYBtgaNNSrj7wyqfresYG24h0cCSAg8ctG24CgrXc+kJF0rxHXuGjMSy0K22u3X/2CHRGGCmejFhbKI4Jg8FX+mZvG+7yMsQNVrx2Qzh1OSTHmd52nt7BW7mMrO7r3KYO7WzjeHtgwMp5/ZSPxsCkqLPf9Y3yzG+zwiwwZGrsSogVQ==';
- $aop->format = "json";
- $aop->charset = "UTF-8";
- $aop->signType = "RSA2";
- $aop->alipayrsaPublicKey = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArHwMZtNYBkK5q2jQ0Ml18H8MhQX9Bpuz/ignvuJC47K7LHY+F6/U/+o/nYeDhqHzUajMAAyM06N3r2qBnWQRjC4JKFMO4i5xIDVycuumzcsWz3LwAkHOFG/S1pGXFWh74zdQDNednhvnNOiTDwjefZRnf5HUqEZK/7tRSaZvzSUIAwHG2zj0C6AYkhg5wr6ZJxgRDjPjqbs6ZMqLT+pITsnCcc6IgIisZbPTdtw1U2FKmQm5n228drI3XKYbE3UVT2y6R0mZNmqmiHDszmYSKOjDrpgtMExWpee8kUFn7J800HIyYtq0nRv1ypdWngUZtkm+szVWOTDGgN4eHQW3FwIDAQAB';
- $data = [
- 'apiname'=>'com.alipay.account.auth',
- 'method'=>'alipay.open.auth.sdk.code.get',
- 'app_id'=>'2021001197654668',
- 'app_name'=>'mc',
- 'biz_type'=>'openservice',
- 'pid'=>'2088931546284482', //合作伙伴身份(PID):
- 'product_id'=>'APP_FAST_LOGIN',
- 'scope'=>'kuaijie',
- 'target_id'=>"ALI".time().rand(10000,99999),
- 'auth_type'=>'AUTHACCOUNT',
- 'sign_type'=>'RSA2'
- ];
- $sign = $aop->generateSign($data,"RSA2");
- $paramStr = '';
- foreach ($data as $key => $param) {
- $paramStr .= "{$key}={$param}&";
- }
- $paramStr = $paramStr.'sign='.urlencode($sign);
- return $paramStr;
- }
- /*
- * 支付宝登录验证
- * $userId 支付宝用户唯一id
- * */
- public function aliCheck($userId){
- $user = Db::name("user")->where(['ali_user_id'=>$userId])->find();
- //判断是否是第一次登录
- if($user){
- //成功登录业务逻辑
- if (!$user['account']) {
- return ['code' => 400, 'msg' => '请绑定手机号'];
- } else {
- return ['code' => 200, 'msg' => '登陆成功', 'user' => $user];
- }
- }else{
- return ['code' => 400, 'msg' => '请绑定手机号'];
- }
- }
- /*微信信息获取*/
- public function getWechat(){
- $data['appid'] = "wxbf753066ac8686ba";
- $data['appsecret'] = "68943fc124568c4ab4c3f089b7cdf2aa";
- return $data;
- }
- /*微信登录验证
- $openid 微信openid
- */
- public function wechatCheck($openid){
- $user = Db::name("user")->where(['wechat_user_id'=>$openid])->find();
- //判断是否是第一次登录
- if($user){
- //成功登录业务逻辑
- if (!$user['account']) {
- return ['code' => 400, 'msg' => '请绑定手机号'];
- } else {
- return ['code' => 200, 'msg' => '登陆成功', 'user' => $user];
- }
- }else{
- return ['code' => 400, 'msg' => '请绑定手机号'];
- }
- }
- /**
- * 微信登录验证一壶茶
- * @param $openid
- * @return array
- * @throws DataNotFoundException
- * @throws DbException
- * @throws ModelNotFoundException
- */
- public function wechatCheckYhc($openid){
- $enterprise_user = Db::name("enterprise_user")->where(['openid'=>$openid])->find();
- //判断是否是第一次登录,成功登录业务逻辑
- if($enterprise_user && $enterprise_user['uid']!=0){
- $user = Db::name("user")->where(['uid'=>$enterprise_user['uid']])->find();
- return ['code' => 200, 'msg' => '登陆成功', 'user' => $user];
- }
- return ['code' => 400, 'msg' => '请绑定手机号'];
- }
- /*微信支付宝绑定*/
- public function thirdBinding(string $phone, ?string $pwd, $user_type = 'APP',$third_user_id='',$type=0,$url)
- {
- $pwd = $pwd ? $this->encodePassword($pwd) : $this->encodePassword($this->dao->defaultPwd());
- $user = $this->accountByUser($phone);
- if($user){
- $data = [
- 'last_ip' => app('request')->ip(),
- ];
- }else{
- $data = [
- 'account' => $phone,
- 'pwd' => $pwd,
- 'nickname' => '用户' . substr($phone, 7, 4),
- 'avatar' => $url.'/uploads/logo.jpg',
- 'phone' => $phone,
- 'last_ip' => app('request')->ip(),
- ];
- }
- if($type ==1){
- if(isset($user->wechat_user_id) && $user->wechat_user_id){return true;}//这里可能有问题
- $data['wechat_user_id'] = $third_user_id;
- }elseif($type ==2){
- if(isset($user->ali_user_id) && $user->ali_user_id){return true;}
- // if($user->ali_user_id){return true;}
- $data['ali_user_id'] = $third_user_id;
- }
- if(!$user){
- return $this->create($user_type, $data);
- }else{
- Db::name("user")->where(['account'=>$phone])->update($data);
- return $user;
- }
- }
- public function getTokenByCode($authorization_code,$info=false,$type=123)
- {
- try {
- $aop = new AopClient();
- $aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
- if($type=='h5'){
- $aop->appId = '2021001197698727';
- $aop->rsaPrivateKey = 'MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCf1r70C/D+XWtDuuV07/41UnEHRyas0Y92TRS5eI+S4v4r8lDY8aLcWM6ssE/dVaKrGulEqG3jv12WLRP7ZDiHSzlcgrHZLm9sub+rY9r7dPMn69xaVg/wMh7SQ5yduHXr1WtjIlnb4ng29ZoQjzHy9kgQ0i92Vtk1PRsQrlUWeYGXjftBShdHMraP7km8tvA5S+tTalczzkDm5i2lXHeycAkIiTJ1dqebA74ZCe47kyG0AtNbRBOMOB0zOFcHX865Faa1hPPlug98o6D6oyR4M/rkehqtf1Y1AIuBGIDSey4BmOvIqOiu/WbLTSx7TS9OxXBoP3SFMKiVKMqR7yH5AgMBAAECggEAGf3QpVy/vo0wYR4mK+LOwpr6WEWgq1+UZZdZNGO/bRJOZJUNwolgg1ZJnVk6U3KWdh51Kj39SJiYvk/sPOfqLU31MO7rvrZHVjXKTjN5q4Qz+hzngyUViGiODIEEGb2iJ0xYHxG57QChrcY4XFL8u1aDF4EmSKcMwRSDry26FmI/uEfjuF30kl11r24CtifE/NkbnqeWzOvoXteWxb1DbUsiqjRydnqUme5BPNoFhp5maYMZVUyg+I92G39FlQ1xQSJVq68TpL7ePOf8JBrGLqHSqNAiAfFwuvUWpELBstc4GPvQeWAw8142dsQGWz2wHZjUZW9CEyfrPDXZUz2wkQKBgQDdzpWkLNSjqhzdxcWw6z4bTguRVc594s5wbMftrKEybVbutVYjVKYi3rzSRRMcbr7vkkCj7FkQsmjY5l/wrv/CBrN/OPhQ7dDGTdEjtU2pnhDOvLaXIvcinz9YeAVHGePXXyx43wo5LysCqhAIxA5lS+LOuZZxQJzYVOv18uI6NQKBgQC4eqT8DiYb81Ke5l4Q5irOOd9Q/PqtCDJAyOkZVjMKBNOJauHZdx+rFgB2GEB2EdI5rUPDLn4XBkmeHlqk15HjLGA2kl4AojB2eCfD9voYHOTOEiAGpm9AL9Ws8ALFg27W1XKu/Ih1IxHifCAeR86lnIejJCizQ/P2lilWBj9hNQKBgQC8E9cZbhYkbTOq7W9TNDXmi0gNxXehkPdBp0vkAhRxoPss0ECpFrcFLF9p4L5yxolKtXXwSZHAMbfr63SArrMZv/rmLtWIMg9sh0GGiM7Au9I+qxAcmb568hORnbvD7XUgA4i/OUj+8jsDOFb+R9h5Fl7MsduaTpJwcZnfZENl3QKBgEKMq9vp1sGag6GjBSgfgC2pHvB+cofdPxOz5rMnL35bw1v9XMAwgxIa+8uecBKn1yjLYniU2xO/Ruttk9GHmq9TINpO7u5XlBgIvH+rJwlv0vKsAzWi8Ns85l5erwFFqsSBd7+8hhWLszX7BTMnQFrqHtwxfSU+TFIWVY8c7dxJAoGAaXqh1VejqHCPLfQ7Dthx0lEkzXOdUaPVh+LW7F5RPCBBnhsaFGlKVOQYHm6oFtH9qLgZBT1IkA7HTGX9YYTX8jl1zvgUNvxFOprPyYCo5O7vsa7KfkIzZt2FnycI83NAKYDTpA8q28YI81rcHcRLRbmun2drEPyj9dG79uy6Xg8=';
- $aop->alipayrsaPublicKey='MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArHwMZtNYBkK5q2jQ0Ml18H8MhQX9Bpuz/ignvuJC47K7LHY+F6/U/+o/nYeDhqHzUajMAAyM06N3r2qBnWQRjC4JKFMO4i5xIDVycuumzcsWz3LwAkHOFG/S1pGXFWh74zdQDNednhvnNOiTDwjefZRnf5HUqEZK/7tRSaZvzSUIAwHG2zj0C6AYkhg5wr6ZJxgRDjPjqbs6ZMqLT+pITsnCcc6IgIisZbPTdtw1U2FKmQm5n228drI3XKYbE3UVT2y6R0mZNmqmiHDszmYSKOjDrpgtMExWpee8kUFn7J800HIyYtq0nRv1ypdWngUZtkm+szVWOTDGgN4eHQW3FwIDAQAB';
- }else if ($type == 'h5pay'){
- $aop->appId = '2021003191617008';
- $aop->rsaPrivateKey = 'MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQC9fXH7s0dBJ6y7K4M9rhsAf4MMYaOb/V7rIrmh1EJB1msW9QprLEIKIlmn4289/CRTXzVAOk9xWI6ROesq/C0RVh7ZxyM4Gm++znW+eoBsWXsmsMHuvKrrI+rec0JG4d/iWhy8j2YPhn/s3xo1/lHzdo7F0y0waJZdkzFErpO0bra+TtB6QpM3EXZFZ5FAw14bGJklI4mU14B50JLKSXPUJpm+B32OAWhz7FFdC+HIT22ZOAjFicPUwmn/8kzkV6ukPXpVHdp2EBRaH7EmBYw49ICp0YotHroFJVMRqzCeff5or8CBRv528zAAB0Q+jBxIhVbQebHLnrtVy2j+e/S1AgMBAAECggEBAIdmFMVitD6VR/KyQ+QV/Utc0dpOBmdXI7Tmqjg9gF6lBP5xd9Fe3Y16QBAcDof/HEHKnTVYtR1rxut0tFqRuO5TWFYK2lqjYUe5JR9HT26cfcgGs3yQqZy9nHz5ZNlbWuvVsgT2floHpG8wd/0uzYYnKBupKvgVM6SHocPO7tIUsxw9dGYdKrZnES6YbjlpPen7VUgvvdCWlaOooQNFEdqkgFywO9qxcVZ9kiE/0QijbAnJPaf9yvYqRRPqgydBDDBiSVklwyqaNcXj7vWeJi40oXBKhzHcPhkE7pWkc1eNjCx/SpAt1dAbgXoXpJsYba6VnxVfTUw5uHewko0H1AECgYEA6I+pE5WKRxWlbe09EDaO2FIzY5HWn463P3Is8StywnHbr27mqi8WmL0Re0ptRS5G1Xw/7yfRot1eLLZ0PoAd1/+ubd3MdhfFFYKhcTDxlrC56okVFYjz9JTF5WLwNG+aoeVzfhZuurqaPowEyTRM27y0WluTCvxaINNtg5rE7QECgYEA0JaAKs8pYIHd35YnsJAPaEvQ4fWbonUkOiEpZznKr/bU8aOO4NXs9aoZ/VXmBYscyjmpjVhF+TOr7EI37dVIFNpJ0eS9H2Bpdv0B2x7++qFxOmAQBFTQyL6wQt6j7p7JXP5TlH3mRpnAnxJ9FXssJxfYGwmSOcjOZhkHXMSZY7UCgYEAjhV3TyfF27g14ftXm1g53aAbFXI8li8zdefj3VSWQIYfmgc/lio+vAKHc7P9Ho8vZ68JwKurQL3Ok7LFQoozsYvcnfMsv9m153Zv/B/S+iXu8IPgBdAue/eJEKRp7R9ichclgJtj+2GWazBQnDz/2CBqb+oS5FtZFUUXW5hrSAECgYARsWJnvzC8Tee7CmqNcHrOFvg94m50JkmPYLa5Wc6WhHJlmMEK0zqJUAdqVLnxKG6lvKRkJ+OvkrF3ldpWoyu9ERMH6cYc/jmT7TwWERgBvGX1VKanJ2aaUIp08ZuoJvHfoHcIdnFs9afAFnpjsxH4su4SxQoROrY/NMpKFScJrQKBgQClpi0+cJOqK4XHaM3jfW4+vfHKJSR/kuDp3WgDirkeD3NnS8BUMWeIYNGsF0vs6NYk5ux95RObn+Ih++NkkrSsH7+z40LXYLePYK9h7M0anRTFlBuFUM5matclvtlJiET4o+w6thQIIv0Mhmo4ZHrLBsnqsOsbWnh6o0gtWqVKxQ==';
- $aop->alipayrsaPublicKey='MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuUb+0sJSNXjWiG0VJIPzn55+18af/fubYMpRLlreu34ewMgLx1zpCNpB3wrA+dylfWPMAm8PzvKnakByB+VJ/LMNhWHmF8Qkdo4astAikjlI4TMQCK/G384NzrtjHR4DGCDM5CMVt1xw5noF7kNBMYIvgDfhMCYmygdlIjuVdIlVEoQKOsT0RaNMleES0aZvbjvBGkGM0dsetqUExSjid9BF1NAO2ET+J3XMxCtMgCUVmFUvxsCKe6Rapa1/Lk3rzIeG6CRpoabuYfPM9E+3y3f3luSOMXLfH9lOSW1RA8qrF+Ms1RZv8gmzUnbyrPLmmZPmmN/Qs6DGzDVg73fpSwIDAQAB';
- }else{
- $aop->appId = '2021001197654668';
- $aop->rsaPrivateKey = 'MIIEpAIBAAKCAQEAlGWxvrR9KGkheEK4kTrcKDvK3ovhwi+zc4zxa11DZgpyUk2Kr2RT08ZQPaQLm9jQFlzwzqVgbAL9DFBTRAaD4nEMHoR0ZfR9ueRirko16Kjkx8AOPVYdEIy68U01gln/N9Y0iq8YVxu4Yv8vorY7U8aSJUcAnkx9bPbhei8SZxVgC2KldextzyVh9t/tAk2WAxbLmvieF746lY1u0W6AfmBIvQWdjbw3wJUMxMYrlp501zHr7kecgcYhnOnYkO9ehpVSAYJHoDDAulBEkapiSGiP09aOe3jhsutFDIrxL4BoFyNtaAOCbh6sUa9mMNu67wRBXwitfK7wOdt1gzfmOwIDAQABAoIBAQCODzQyzfGqh8nkqGqrjN9JHMQ+e0ZpcOSnT1ulXiixPHroUxbahH7DEuuptqruTIYXgm18RVCi1dGMwjCTxHDoizQA2ufa2kypcfsNwjkNOvGYT0DScudr+mzTpwf8e08ZEtRFlw0EBqNjEct2RmFQ95zcVrY+1BaWA1kicIF7b7/Zto7x7xAnR10tfRE2bUePBzruugZRk+Z9LbcKSRDAb/JBEFKHzfiBIFyIcEj9covcNVFF8QCkraxugDxH0dxYheFz7sxvjLyo2OYW+Xs2Q95/kVZIGWdz2T4IIqdvqjWzCn+azMvpB7056ziFrit6E2JNQH+8DrWsHj2b3xnhAoGBAOFwF44Qce7c9zTnvzZZlqONuHrzhsSxvHEU2mf+FitpFFASOhJcPoK18M0ZsUX7EwVQLCKSoKcdk34Y3msM0E+aihRpwBQbR1isdnSnbTcBRRpmVHnX50qXjHabvY4lPJQssMKsf0ezitFQP1NA7oNWhJzEDTRNZxqlo4Y3JGf5AoGBAKiD4MKR24l9EJ+aMnPW50jIkNj/sWslYTZn5b7zyt3e1gj39Er5ePCgzqVmKt5SK/SnS1PxEcQurVuw2Gs4/9vAYc25QAAYhZCbgHRTUhv1+1xontLyIIXChQABJElAEkTj+bpB5ps/rwOVR3znMyS1135o4Q+DyP+SW7BZ/NTTAoGBANp+J3Y7HhGh+7489igZAFUYIDqaGH4+vSLkUSIFMztzpopMgBgXa0aITBCc3CG1TCQUJhKEBkyx76eBNuCOFL9ySm2qaM2T+rxIuq4pL0LmajFCCJHm3XaAF1VFcJx6HpKGFfM3+ExoCR0BJ77q6cBFdFXz9dBBTLKY4zpL628RAoGAUeARejen9PtA8mrXDJVjtmdMiUJij26P9wEwDUEiVf6I+76NgUgIzNE01gP33CEMnkgSP2yndyw+qogX/rCpD7o/StcxE1rWulXzaZF6GX/Aazuhv1hJGPRT7pafbL+moLYrhaWzR8b/X7xOCY/Dt5hqZU7L2t/q7tHLnrl6MGUCgYBtgaNNSrj7wyqfresYG24h0cCSAg8ctG24CgrXc+kJF0rxHXuGjMSy0K22u3X/2CHRGGCmejFhbKI4Jg8FX+mZvG+7yMsQNVrx2Qzh1OSTHmd52nt7BW7mMrO7r3KYO7WzjeHtgwMp5/ZSPxsCkqLPf9Y3yzG+zwiwwZGrsSogVQ==';
- $aop->alipayrsaPublicKey = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArHwMZtNYBkK5q2jQ0Ml18H8MhQX9Bpuz/ignvuJC47K7LHY+F6/U/+o/nYeDhqHzUajMAAyM06N3r2qBnWQRjC4JKFMO4i5xIDVycuumzcsWz3LwAkHOFG/S1pGXFWh74zdQDNednhvnNOiTDwjefZRnf5HUqEZK/7tRSaZvzSUIAwHG2zj0C6AYkhg5wr6ZJxgRDjPjqbs6ZMqLT+pITsnCcc6IgIisZbPTdtw1U2FKmQm5n228drI3XKYbE3UVT2y6R0mZNmqmiHDszmYSKOjDrpgtMExWpee8kUFn7J800HIyYtq0nRv1ypdWngUZtkm+szVWOTDGgN4eHQW3FwIDAQAB';
- }
- $aop->apiVersion = '1.0';
- $aop->signType = 'RSA2';
- $aop->postCharset='UTF-8';
- $aop->format='json';
- $request = new AlipaySystemOauthTokenRequest ();
- $request->setGrantType("authorization_code");
- $request->setCode($authorization_code);
- $result = $aop->execute($request);
- if (isset($result->alipay_system_oauth_token_response->user_id)) {
- $return['user_id'] = $result->alipay_system_oauth_token_response->user_id;
- $return['msg'] = $result->alipay_system_oauth_token_response->access_token;
- $access_token=$return['msg'] ;
- } else {
- $return['code'] = $result->error_response->code;
- $return['msg'] = $result->error_response->sub_msg;
- return $return;
- }
- if ($info){
- $request = new AlipayUserInfoShareRequest();
- $result = $aop->execute ( $request ,$access_token);
- $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
- Db::name('log')->insert(['data'=>\GuzzleHttp\json_encode($responseNode)]);
- $resultCode = $result->$responseNode->code;
- Db::name('log')->insert(['data'=>$resultCode]);
- $userData=json_decode(json_encode($result->$responseNode),true);
- if(!empty($resultCode)&&$resultCode == 10000){
- return $userData;
- }
- }
- return $return;
- } catch (\Throwable $w) {
- Db::name('log')->insert(['data'=>json_encode($w->getMessage())]);
- return $w->getMessage();
- }
- }
- /**
- * @param $id
- * @return Form
- * @throws DataNotFoundException
- * @throws DbException
- * @throws ModelNotFoundException
- * @throws FormBuilderException
- * @author xaboy
- * @day 2020-05-07
- */
- public function changePassForm($id)
- {
- return Elm::createForm(Route::buildUrl('systemUserChangePass', compact('id'))->build(), [
- Elm::input('pass_word', '用户密码')->required()->value("")
- ])->setTitle('修改用户密码');
- }
- public function changePass($uid,$password)
- {
- $pass_word=$this->encodePassword($password);
- $data= Db::name("user")->where(["uid"=>$uid])->update(['pwd'=>$pass_word]);
- if($data){
- return $data;
- }else{
- return false;
- }
- }
- public function wechatGetTokenBycode()
- {
- }
- public function createUserNumber($uid){
- $t = "C";
- $number = '000000000';
- if($uid <= 10){
- $uid = $uid . 'X';
- }
- $strlen = mb_strlen($uid);//id长度
- $newNumber = $t.substr_replace($number,$uid,-$strlen);
- $newNumber = str_replace('4','R',$newNumber);
- Db::name('user') -> where(["uid"=>$uid])->update(['user_number'=>$newNumber]);
- }
- /**
- * @param int $uid 用户ID
- * @param string $score 积分
- * @param int $status 积分状态
- * @param string $mark 备注
- * @param string $has_qian 连续签到天数
- * @param string $today_signintime 签到时间
- * @param int $order_id 订单ID
- * @param int $pm 1-收入。2-支出
- * @param string $order_type
- * @throws DbException
- */
- public function sign_add($uid, $score, $status, $mark, $has_qian = '', $today_signintime = '', $order_id = 0, $pm = 1, $order_type = '',$type='',$settlement_time = '')
- {
- if(!in_array($type,[1,2])){
- // 其他情况都直接返回,因为目前只有365专区购买才可以获得
- return false;
- }
- $ins_data['uid'] = $uid;
- $ins_data['continuity_day'] = $has_qian;
- $ins_data['reward_socre'] = $score;
- $ins_data['signin_time'] = $today_signintime;
- $ins_data['addtime'] = time();
- $ins_data['status'] = $status;
- $ins_data['mark'] = $mark;
- $ins_data['type'] = $type;
- $ins_data['settlement_time'] = $settlement_time;// 结算时间 真正到了结算时间会结算
- $ins_data['order_id'] = $order_id;
- $ins_data['pm'] = $pm;
- $ins_data['order_type'] = $order_type;
- Db::name('user_sign_score')->insertGetId($ins_data);
- if($pm == 1 && $status == 1){
- Db::name('user')->where('uid',$uid)->inc('score', $score)->update();
- }
- if($pm == 2){
- Db::name('user')->where('uid', $uid)->dec('score', $score)->update();
- }
- }
- public function gold_add($uid,$gold,$mark,$pm=1){
- $ins['uid'] = $uid;
- $ins['gold'] = $gold;
- $ins['mark'] = $mark;
- $ins['time'] = time();
- $ins['pm'] = $pm;
- $id = Db::name('user_gold_log')->insertGetId($ins);
- if($pm == 1){
- Db::name('user_gold')->where('uid',$uid)->inc('now_gold', $gold)->inc('cumulative', $gold)->update();
- }else{
- Db::name('user_gold') -> where('uid',$uid) -> dec('now_gold', $gold)->update();
- }
- $surplus = Db::name('user_gold')->where('uid',$uid)->value('now_gold');
- Db::name('user_gold_log') -> where('id',$id) -> update(['surplus'=>$surplus]);
- }
- function get_level_list(){
- try {
- $tokenInfo = (request()->tokenInfo());
- if(isset($tokenInfo->jti[1]) && $tokenInfo->jti[1]=='admin') {
- $admin_id = request()->adminId();
- $roles_str = Db::name('system_admin')->where('admin_id', $admin_id)->value('roles');
- $phone_count = Db::name('system_role')->whereIn('role_id', $roles_str)->where("phone !=''")->count();
- if ($phone_count) {
- return true;
- }
- }
- }catch (Exception $e) {
- return false;
- }
- return false;
- // $phone_data=Db::name('system_role')->whereIn('role_id',$roles_str)->where("phone !=''")->group("phone")->column('phone');
- // if($phone_data){
- // $uid_data = Db::name('user')->whereIn('phone', $phone_data)->column('uid');
- // if($uid_data){
- // $uids=$this->level_list($uid_data,0);
- // }
- // }
- // }
- // return isset($uids)?$uids:[];
- }
- // function level_list($uid_data,$i){
- // $i++;
- // $uid = Db::name('user')->whereIn('level_id', $uid_data)->column('uid');
- // if($uid && $i<9){
- // $uid_data=array_merge($uid_data,$uid);
- // return $this->level_list($uid_data,$i);
- // }else{
- // return $uid_data;
- // }
- // }
- public function sign_yhc_add($uid,$mer_id,$score,$mark,$order_id=0,$pm=1,$use_uid=0){
- $ins_data['uid'] = $uid;
- $ins_data['mer_id'] = $mer_id;
- $ins_data['mark'] = $mark;
- $ins_data['order_id'] = $order_id;
- $ins_data['pm'] = $pm;
- $ins_data['reward_socre'] = $score;
- $ins_data['use_uid'] = $use_uid;
- try {
- Db::transaction(function () use ($ins_data,$pm,$mer_id,$score,$uid) {
- $id = Db::name('enterprise_user_score')->insertGetId($ins_data);
- if($pm == 2){
- Db::name('enterprise_user') -> where('uid',$uid)-> where('mer_id',$mer_id) -> dec('green_integral',$score)->update();
- }else if ($pm==1){
- Db::name('enterprise_user') -> where('uid',$uid)-> where('mer_id',$mer_id) -> inc('green_integral',$score)->update();
- }
- $green_integral=Db::name('enterprise_user')->where('mer_id',$mer_id)->where('uid',$uid)->value('green_integral');
- if($green_integral<0){
- throw new \Exception('修改失败,用户红积分不足,请刷新后再试');
- }
- });
- }catch (\Exception $e){
- return false;
- }
- return true;
- }
- /**
- * 获取下级所有团队列表
- * @param $uid
- * @return int
- */
- public function getSpreadUidBreak($uid){
- $sql = "select getUserSpreadId($uid) as uids";
- $count = Db::query($sql);
- $count[0]['uids'] = trim($count[0]['uids'],'$,');
- $originalArray = explode(",",$count[0]['uids']);
- $resultArray = array_diff($originalArray, [$uid]);
- return $resultArray;
- }
- }
|