123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227 |
- <?php
-
-
- namespace app\api\controller\v1;
-
- use think\Db;
- use think\Request;
-
- class Users extends Base
- {
- public $users;
- public $users_id;
-
-
-
- public function _initialize()
- {
- parent::_initialize();
- $this->users = $this->getUser();
- $this->users_id = !empty($this->users['users_id']) ? intval($this->users['users_id']) : null;
- if (empty($this->users_id)) $this->error('请先登录');
- }
-
-
-
- public function order_lists($dataType)
- {
- $list = model('v1.Shop')->getOrderList($this->users_id, $dataType);
- return $this->renderSuccess(compact('list'));
- }
-
-
- public function guestbook_list()
- {
- if (IS_AJAX) {
- $list = model('v1.User')->guestbookList();
- return $this->renderSuccess(compact('list'));
- }
- $this->error('请求错误!');
-
-
- }
-
-
- public function get_book_detail()
- {
- if (IS_AJAX) {
- $param = input('param.');
- $list = model('v1.User')->GetMyBookDetail($param);
-
- return $this->renderSuccess(compact('list'));
- }
- $this->error('请求错误!');
- }
-
-
- public function cancel_book()
- {
- if (IS_AJAX) {
- $aid = input('param.aid/d',0);
- if (empty($aid)){
- $this->error('缺少参数aid!');
- }
- $r = Db::name('guestbook')
- ->where(['aid'=>$aid,'users_id'=>$this->users_id])
- ->delete();
- if (false !== $r){
- Db::name('guestbook_attr')->where('aid',$aid)->delete();
- $this->success('取消成功!');
- }else{
- $this->error('取消失败!');
- }
- }
- $this->error('请求错误!');
- }
-
-
-
-
- public function order_cancel($order_id)
- {
- if (IS_AJAX_POST && !empty($order_id)) {
- model('v1.Shop')->orderCancel($order_id, $this->users_id);
- }
- $this->error('订单取消失败!');
- }
-
-
-
- public function order_remind($order_id)
- {
- if (IS_AJAX_POST && !empty($order_id)) {
- model('v1.Shop')->orderRemind($order_id, $this->users_id);
- }
- $this->error('订单取消失败!');
- }
-
-
-
- public function order_detail($order_id)
- {
- if (IS_AJAX) {
-
- $is_querykd = 0;
- if (is_dir('./weapp/Querykd/')) {
- $count = Db::name('weapp')->where(['code'=>'Querykd', 'status'=>1])->count();
- $is_querykd = empty($count) ? $is_querykd : 1;
- }
-
- $detail = model('v1.Shop')->getOrderDetail($order_id, $this->users_id);
- return $this->renderSuccess([
- 'order' => $detail,
- 'is_querykd' => $is_querykd,
- 'setting' => [],
- ]);
- }
- $this->error('订单读取失败!');
- }
-
-
-
- public function order_pay($order_id, $payType = 20)
- {
-
- $order = model('v1.Shop')->getOrderDetail($order_id, $this->users_id);
-
- if (!isset($order['order_status']) || $order['order_status'] != 0) {
- $this->error('很抱歉,当前订单不合法,无法支付');
- }
-
- $payment = model('v.Shop')->onOrderPayment($this->users, $order, $payType);
- if (isset($payment['code']) && empty($payment['code'])) {
- $this->error($payment['msg'] ?: '订单支付失败');
- }
-
- $this->renderSuccess([
- 'order_id' => $order['order_id'],
- 'pay_type' => $payType,
- 'payment' => $payment
- ], ['success' => '支付成功', 'error' => '订单未支付']);
- }
-
-
-
- public function order_express($order_id, $timestamp = '')
- {
-
- $detail = model('v1.Shop')->getOrderDetail($order_id, $this->users_id);
- if (empty($detail['express_order'])) {
- return $this->error('没有物流信息');
- }
-
-
- $express = model('v1.Shop')->orderExpress($detail['express_name'], $detail['express_code'], $detail['express_order'], $timestamp);
- if (!empty($express)) {
- return $this->renderSuccess(compact('express'));
- }
- $this->error('没有找到物流信息!');
- }
-
-
-
- public function order_receipt($order_id)
- {
- if (IS_AJAX_POST && !empty($order_id)) {
- model('v1.Shop')->orderReceipt($order_id, $this->users_id);
- }
- $this->error('确认收货失败!');
- }
-
-
-
-
-
- public function shop_add_cart()
- {
- if (IS_AJAX_POST) {
- $post = input('post.');
-
- if (empty($post['product_num']) || 0 > $post['product_num']) $this->error('请输入数量');
-
-
- $post['users_id'] = $this->users_id;
-
-
- $ShopModel = model('v1.Shop');
-
-
- $ShopModel->IsSoldOut($post);
-
-
- $ShopModel->ShopAddCart($post);
- }
- }
-
-
-
- public function shop_page_add_cart()
- {
- if (IS_AJAX_POST) {
- $post = input('post.');
-
- if (empty($post['product_num']) || 0 > $post['product_num']) $this->error('请输入数量');
-
- $post['users_id'] = $this->users_id;
-
-
- $ShopModel = model('v1.Shop');
-
-
- $ShopModel->ShopPageAddCart($post);
- }
- }
-
-
-
- public function shop_buy_now()
- {
- if (IS_AJAX_POST) {
- $post = input('post.');
-
- if (empty($post['product_num']) || 0 > $post['product_num']) $this->error('请输入数量');
-
-
- $post['users_id'] = $this->users_id;
-
-
- $ShopModel = model('v1.Shop');
-
-
- $ShopModel->IsSoldOut($post);
-
-
- $ShopModel->ShopBuyNow($post);
- }
- }
-
-
-
- public function shop_product_buy()
- {
- if (IS_AJAX_POST) {
-
- $querystr = input('param.querystr/s');
- if (empty($querystr)) $this->error('无效链接!');
-
-
- $ShopModel = model('v1.Shop');
-
-
- $post = input('post.');
- $ShopModel->GetProductData($querystr, $this->users_id, $this->users['level_discount'], $this->users, $post);
- }
- }
-
-
-
- public function shop_order_pay()
- {
- if (IS_AJAX_POST) {
- $post = input('post.');
- $post['action'] = !empty($post['action']) ? $post['action'] : 'CreatePay';
-
-
- $post['users_id'] = $this->users_id;
- $post['openid'] = Db::name('wx_users')->where('users_id', $this->users_id)->getField('openid');
-
-
- $ShopModel = model('v1.Shop');
-
-
- if ('DirectPay' == $post['action']) {
-
- $ShopModel->OrderDirectPay($post);
- } else if ('CreatePay' == $post['action']) {
-
- if (empty($post['querystr'])) $this->error('无效链接!');
-
-
- $ShopModel->ShopOrderPay($post, $this->users['level_discount'], $this->users['level_id'], $this->users);
- }
- }
- }
-
-
-
- public function shop_order_pay_deal_with()
- {
- if (IS_AJAX_POST) {
- $post = input('post.');
-
-
- $post['users_id'] = $this->users_id;
- $post['openid'] = Db::name('wx_users')->where('users_id', $this->users_id)->getField('openid');
-
-
- if (9 === intval($post['curPayType'])) {
-
- model('TikTok')->tikTokAppletsPayDealWith($post);
- } else {
-
- model('v1.Shop')->WechatAppletsPayDealWith($post);
- }
- }
- }
-
-
-
- public function shop_cart_action()
- {
- if (IS_AJAX) {
- $param = input('param.');
- if (empty($param['action'])) $param['action'] = null;
- $param['users_id'] = $this->users_id;
-
-
- $ShopModel = model('v1.Shop');
-
-
- if ('add' == $param['action']) {
-
- $ShopModel->ShopCartNumAdd($param);
- } else if ('less' == $param['action']) {
-
- $ShopModel->ShopCartNumLess($param);
- } else if ('selected' == $param['action']) {
-
- $ShopModel->ShopCartSelected($param);
- } else if ('all_selected' == $param['action']) {
-
- $ShopModel->ShopCartAllSelected($param);
- } else if ('del' == $param['action']) {
-
- $ShopModel->ShopCartDelete($param);
- } else {
- $this->error('请正确操作');
- }
-
-
- }
- }
-
-
-
- public function shop_address_list()
- {
- if (IS_AJAX) {
-
- $ShopModel = model('v1.Shop');
-
-
- $ReturnData = $ShopModel->GetAllAddressList($this->users);
- }
- }
-
-
-
- public function shop_address_action()
- {
- if (IS_AJAX_POST) {
- $post = input('post.');
-
- $ShopModel = model('v1.Shop');
-
-
- if ('find_add' == $post['action']) {
-
- $ShopModel->FindAddAddr($post, $this->users_id);
- } else if ('find_edit' == $post['action']) {
-
- $ShopModel->FindEditAddr($post, $this->users_id);
- } else if ('default' == $post['action']) {
-
- $ShopModel->SetDefaultAddr($post, $this->users_id);
- } else if ('find_detail' == $post['action']) {
-
- $ShopModel->GetFindAddrDetail($post, $this->users);
- } else if ('find_del' == $post['action']) {
-
- $ShopModel->FindDelAddr($post, $this->users_id);
- } else {
- $this->error('请正确操作');
- }
- }
- }
-
-
-
-
- public function order_comment($order_id)
- {
- if (IS_AJAX) {
- $data = model('v1.Shop')->getOrderComment($order_id, $this->users_id);
- return $this->renderSuccess([
- 'goods' => $data,
- ]);
- }
- $this->error('读取失败!');
- }
-
-
-
- public function save_comment()
- {
- if (IS_AJAX_POST) {
- $post = input('post.');
- return model('v1.Shop')->getSaveComment($post,$this->users_id);
- }
- $this->error('评价失败!');
- }
-
-
-
- public function get_coupon($coupon_id)
- {
- if (IS_AJAX) {
- $where = [
- 'coupon_id' => $coupon_id,
- ];
-
- $coupon = Db::name('shop_coupon')->where($where)->find();
- if (!empty($coupon)) {
- if (1 > $coupon['coupon_stock']) {
- $this->error('优惠券库存不足!');
- }
- if (getTime() > $coupon['end_date']) {
- $this->error('优惠券发放已结束!');
- }
- $where['users_id'] = $this->users_id;
- $where['use_status'] = 0;
- $where['start_time'] = ['<=',getTime()];
- $where['end_time'] = ['>=',getTime()];
-
- $count = Db::name('shop_coupon_use')->where($where)->find();
-
- if (!empty($count)) {
- $this->error('请勿重复领取!');
- } else {
- $insert['coupon_id'] = $coupon_id;
- $insert['coupon_code'] = $coupon['coupon_code'];
- $insert['users_id'] = $this->users_id;
- $insert['use_status'] = 0;
- $insert['get_time'] = getTime();
- $insert['add_time'] = getTime();
- $insert['update_time'] = getTime();
-
- if (1 == $coupon['use_type']) {
- $insert['start_time'] = $coupon['use_start_time'];
- $insert['end_time'] = $coupon['use_end_time'];
- } else if (2 == $coupon['use_type']) {
- $insert['start_time'] = strtotime(date("Y-m-d", time()));
- $insert['end_time'] = $insert['start_time'] + $coupon['valid_days'] * 86400;
- } else if (3 == $coupon['use_type']) {
- $insert['start_time'] = strtotime(date("Y-m-d", time())) + 86400;
- $insert['end_time'] = $insert['start_time'] + $coupon['valid_days'] * 86400;
- }
- if (!empty($insert)) {
- $use_insert = Db::name('shop_coupon_use')->insert($insert);
- if (!empty($use_insert)) {
-
- Db::name('shop_coupon')->where('coupon_id', $coupon_id)->setDec('coupon_stock');
- $this->success('领取成功!');
- }
- }
- }
- }
- }
- $this->error('优惠券领取失败!');
- }
-
-
-
- public function get_my_coupon($dataType)
- {
- $list = model('v1.Shop')->GetMyCouponList($this->users_id, $dataType);
-
- return $this->renderSuccess(compact('list'));
- }
-
-
- public function get_coupon_center()
- {
- $list = model('v1.Shop')->GetCouponCenter($this->users_id);
-
- return $this->renderSuccess(compact('list'));
- }
-
-
-
- public function get_collect()
- {
- if (IS_AJAX_POST) {
- $aid = input('param.aid/d');
- $type = input('param.type/s','users_collection');
- $success = '已收藏';
- $cancel = '已取消';
- if ('users_collection' != $type){
- $success = 'success';
- }else{
- $cancel = 'cancel';
- }
- if(empty($aid)){
- $this->error('缺少文档ID!');
- }
- $count = Db::name($type)->where([
- 'aid' => $aid,
- 'users_id' => $this->users_id,
- ])->count();
- if (empty($count)) {
- $addSave = Db::name('archives')->field('aid,channel,typeid,lang,title,litpic')->where('aid',$aid)->find();
- if(empty($addSave)){
- $this->error('文档不存在!');
- }
- $addSave['lang'] = $this->home_lang;
- $addSave['add_time'] = getTime();
- $addSave['users_id'] = $this->users_id;
- $r = Db::name($type)->insert($addSave);
- if ($r !== false){
- Db::name('archives')->where('aid', $aid)->setInc('collection');
- if ('users_collection' == $type){
- $ret_data = ['is_collect'=>1];
- }else if ('users_like' == $type){
- $ret_data = ['is_like'=>1];
- }
- $this->success($success, null, $ret_data);
- }
- }else{
- $r = Db::name($type)->where(['aid'=>$aid,'users_id'=>$this->users_id])->delete();
- if ($r !== false){
- Db::name('archives')->where('aid', $aid)->setDec('collection');
- if ('users_collection' == $type){
- $ret_data = ['is_collect'=>0];
- }else if ('users_like' == $type){
- $ret_data = ['is_like'=>0];
- }
- $this->success($cancel, null,$ret_data);
- }
- }
- }
- $this->error('请求错误!');
- }
-
-
- public function get_collect_list()
- {
- if (IS_AJAX) {
- $param = input('param.');
- $list = model('v1.User')->GetMyCollectList($param);
-
- return $this->renderSuccess(compact('list'));
- }
- $this->error('请求错误!');
- }
-
-
- public function save_user_info()
- {
- if (IS_AJAX_POST) {
- $head_pic = input('param.head_pic/s');
- $nickname = input('param.nickname/s');
- $nickname = !empty($nickname) ? filterNickname($nickname) : '';
- $mobile = input('param.mobile/s');
- if(!empty($head_pic) || !empty($nickname) || !empty($mobile)){
- $update = ['update_time'=>getTime()];
- if (!empty($head_pic)){
- $update['head_pic'] = $head_pic;
- }
- if (!empty($nickname)){
- $update['nickname'] = $nickname;
- }
- if (!empty($mobile)){
- $is_mobile = check_mobile($mobile);
- if (!$is_mobile){
- $this->error('手机号格式不正确!');
- }
- $update['mobile'] = $mobile;
- $update['is_mobile'] = 1;
- }
- $r = Db::name('users')->where(['users_id'=>$this->users_id])->update($update);
- if (!empty($r)){
- if(!empty($update['mobile'])){
- $para_mobile = Db::name('users_list')->where(['users_id'=>$this->users_id,'para_id'=>1])->find();
- if (!empty($para_mobile)){
- Db::name('users_list')->where(['users_id'=>$this->users_id,'para_id'=>1])->update(['']);
- }else{
-
- }
- }
-
- $this->success('保存成功');
- }
- }
- $this->error('保存失败');
- }
- }
-
-
- public function usersRechargePackAction()
- {
- if (IS_AJAX_POST) {
-
- $param = input('param.');
- $param['terminal'] = 'applets';
- $param['action'] = !empty($param['action']) ? strval($param['action']) : '';
-
-
- $packModel = new \app\common\model\UsersRechargePack($param, $this->users);
-
-
- if ('moneyCenter' == $param['action']) {
- $packModel->usersMoneyCenter();
- }
-
- else if ('recharge' == $param['action']) {
- $packModel->usersRechargePackPage();
- }
-
- else if ('rechargeLog' == $param['action']) {
- $packModel->usersMoneyRechargeLog();
- }
-
- else if ('orderList' == $param['action']) {
- $packModel->usersRechargePackOrder();
- }
-
- else if ('orderCreate' == $param['action']) {
-
- if (!empty($param['pack_id'])) {
- $packModel->usersRechargePackOrderCreate();
- }
-
- else if (!empty($param['users_money'])) {
- $packModel->usersRechargeMoneyOrderCreate();
- }
-
- else {
- $this->error('请选择充值套餐或输入充值金额');
- }
- }
-
- else if ('orderPayHandle' == $param['action']) {
- $packModel->usersRechargePackOrderPayHandle();
- }
- }
- }
-
-
- public function usersCheckIns()
- {
-
- $result = model('ShopPublicHandle')->executeUsersDailyCheckIns($this->users_id);
- if (isset($result['code']) && 1 === intval($result['code'])) {
- $this->success($result['msg'], null, ['scores' => $result['scores'], 'checkInsPoints' => $result['checkInsPoints']]);
- } else {
- $this->error($result['msg']);
- }
- }
-
- public function usersPointsList()
- {
- $param = input('param.');
-
- $result = model('ShopPublicHandle')->getBaseUsersPointsDetails($this->users_id, $param);
-
- $result['users'] = $this->users;
- $this->success('查询成功', null, $result);
- }
-
-
- public function get_phone()
- {
- if (IS_AJAX_POST) {
- $code = input('param.code/s');
- model('v1.User')->getPhone($code);
- }
- }
-
-
- public function HandleUserMoneyAction()
- {
- if (IS_AJAX) {
-
- $param = input('param.');
-
-
- $param['users_id'] = intval($this->users_id);
- $param['moneyid'] = !empty($param['moneyid']) ? intval($param['moneyid']) : 0;
- $param['usersMoney'] = !empty($param['usersMoney']) ? strval($param['usersMoney']) : 0;
- $param['order_number'] = !empty($param['order_number']) ? strval($param['order_number']) : '';
-
- $v1ShopModel = model('v1.Shop');
-
- $action = !empty($param['action']) ? strval($param['action']) : '';
- if ('details' == $action) {
- $v1ShopModel->getUsersMoneyDetails($this->users, $param);
- } else if ('recharge' == $action) {
-
- $v1ShopModel->getUsersMoneyRecharge($param);
- } else if ('rechargePay' == $action) {
-
- $v1ShopModel->getUsersMoneyRechargePay($param);
- }
- }
- }
-
-
- public function handleOrderServiceAction()
- {
- if (IS_AJAX) {
-
- $param = input('param.');
-
-
- $param['users_id'] = intval($this->users_id);
- $param['order_id'] = !empty($param['order_id']) ? intval($param['order_id']) : 0;
- $param['product_id'] = !empty($param['product_id']) ? intval($param['product_id']) : 0;
- $param['details_id'] = !empty($param['details_id']) ? intval($param['details_id']) : 0;
- $param['service_id'] = !empty($param['service_id']) ? intval($param['service_id']) : 0;
-
- $v1ShopModel = model('v1.Shop');
-
- $action = !empty($param['action']) ? strval($param['action']) : '';
- if ('goodsDetect' == $action) {
-
- $v1ShopModel->getOrderGoodsDetect($param);
- } else if ('getServiceList' == $action) {
-
- $v1ShopModel->getOrderGoodsServiceList($param);
- } else if ('getService' == $action) {
-
- $v1ShopModel->getOrderGoodsService($param);
- } else if ('addService' == $action) {
- $v1ShopModel->addOrderGoodsService($param);
- } else if ('cancelService' == $action) {
-
- $v1ShopModel->cancelOrderGoodsService($param);
- } else if ('addUsersDelivery' == $action) {
-
- $v1ShopModel->addServiceUsersDelivery($param);
- }
- }
- }
-
-
- public function dealer_action()
- {
- if (IS_AJAX) {
-
- if (is_dir('./weapp/DealerPlugin/')) {
-
- $data = model('Weapp')->getWeappList('DealerPlugin');
- if (!empty($data['status']) && 1 == $data['status']) {
-
- $dealerPluginLogic = new \app\plugins\logic\DealerPluginLogic($this->users);
- $dealerPluginLogic->dealerAction('', '', 'openSource');
- } else {
- $this->error('请先启用分销插件!');
- }
- } else {
- $this->error('请先安装分销插件!');
- }
- }
- $this->error('请求错误!');
- }
-
-
- public function get_footprint_list()
- {
- if (IS_AJAX) {
- $param = input('param.');
- $list = model('v1.User')->GetMyFootprintList($param);
-
- return $this->renderSuccess(compact('list'));
- }
- $this->error('请求错误!');
- }
-
-
-
- public function set_forward()
- {
- if (IS_AJAX) {
- $users_id = $this->users_id;
- $aid = input('param.aid/d');
- if (empty($aid)){
- $this->error('缺少文档ID!');
- }
-
- $arc = Db::name('archives')
- ->field('aid,channel,typeid,title,litpic')
- ->find($aid);
- if (!empty($arc)) {
- $arc['users_id'] = $users_id;
- $arc['lang'] = $this->home_lang;
- $arc['add_time'] = getTime();
- $arc['update_time'] = getTime();
- Db::name('users_forward')->insert($arc);
- $this->success('保存成功');
- }
- }
- $this->error('请求错误!');
- }
-
-
- public function guestbook($typeid = '')
- {
- $param = input('param.');
- if (IS_POST && !isset($param['apiGuestbookform'])) {
- $post = input('post.');
- $typeid = !empty($post['typeid']) ? intval($post['typeid']) : $typeid;
- if (empty($typeid)) {
- $this->error('post接口缺少typeid的参数与值!');
- }
-
-
- $channel_guestbook_interval = tpSetting('channel_guestbook.channel_guestbook_interval');
- $channel_guestbook_interval = is_numeric($channel_guestbook_interval) ? intval($channel_guestbook_interval) : 60;
- if (0 < $channel_guestbook_interval) {
- $map = array(
- 'ip' => clientIP(),
- 'typeid' => $typeid,
- 'add_time' => array('gt', getTime() - $channel_guestbook_interval),
- );
- $count = Db::name('guestbook')->where($map)->count('aid');
- if (!empty($count)) {
- $this->error("同一个IP在{$channel_guestbook_interval}秒之内不能重复提交!");
- }
- }
-
-
-
- $token = '__token__';
- foreach ($post as $key => $val) {
- if (preg_match('/^__token__/i', $key)) {
- $token = $key;
- continue;
- }
- }
-
-
- foreach ($post as $key => $value) {
- if (stripos($key, "attr_") !== false) {
-
- $attr_id = substr($key, 5);
- $attr_id = intval($attr_id);
- $ga_data = Db::name('guestbook_attribute')->where([
- 'attr_id' => $attr_id,
- ])->find();
- if ($ga_data['required'] == 1 && empty($value)) {
- $this->error($ga_data['attr_name'] . '不能为空!');
- }
-
- if ($ga_data['validate_type'] == 6 && !empty($value)) {
- $pattern = "/^1\d{10}$/";
- if (!preg_match($pattern, $value)) {
- $this->error($ga_data['attr_name'] . '格式不正确!');
- }
- } elseif ($ga_data['validate_type'] == 7 && !empty($value)) {
- $pattern = "/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,})$/i";
- if (preg_match($pattern, $value) == false) {
- $this->error($ga_data['attr_name'] . '格式不正确!');
- }
- }
- }
- }
-
- $newData = array(
- 'typeid' => $typeid,
- 'users_id' => $this->users_id,
- 'channel' => 8,
- 'ip' => clientIP(),
- 'lang' => get_main_lang(),
- 'add_time' => getTime(),
- 'update_time' => getTime(),
- );
- $data = array_merge($post, $newData);
-
-
- $token_value = !empty($data[$token]) ? $data[$token] : '';
- $session_path = \think\Config::get('session.path');
- $session_file = ROOT_PATH . $session_path . "/sess_".str_replace('__token__', '', $token);
- $filesize = @filesize($session_file);
- if(file_exists($session_file) && !empty($filesize)) {
- $fp = fopen($session_file, 'r');
- $token_v = fread($fp, $filesize);
- fclose($fp);
- if ($token_v != $token_value) {
- $this->error('表单令牌无效!');
- }
- } else {
- $this->error('表单令牌无效!');
- }
-
-
- $guestbookRow = [];
-
- $formdata = $data;
- foreach ($formdata as $key => $val) {
- if (in_array($key, ['typeid', 'lang']) || preg_match('/^attr_(\d+)$/i', $key)) {
- continue;
- }
- unset($formdata[$key]);
- }
- $md5data = md5(serialize($formdata));
- $data['md5data'] = $md5data;
- $guestbookRow = M('guestbook')->field('aid')->where(['md5data' => $md5data])->find();
-
-
- $aid = !empty($guestbookRow['aid']) ? $guestbookRow['aid'] : 0;
- if (empty($guestbookRow)) {
- $aid = M('guestbook')->insertGetId($data);
- if ($aid > 0) {
- $res = model('v1.Api')->saveGuestbookAttr($post, $aid, $typeid);
- if ($res){
- $this->error($res);
- }
- }
- } else {
-
- Db::name('guestbook')->where('aid', $aid)->update([
- 'add_time' => getTime(),
- 'update_time' => getTime(),
- ]);
- }
- @unlink($session_file);
- $this->renderSuccess(['aid'=>$aid], '提交成功');
- }
- $this->error('请求错误!');
- }
-
- public function ask_like(){
- model('v1.Ask')->askLike($this->users);
- }
-
- public function add_ask(){
- model('v1.Ask')->addAsk($this->users);
- }
-
- public function add_answer(){
- model('v1.Ask')->addAnswer($this->users);
- }
-
-
- public function media_order_list()
- {
- if (IS_AJAX) {
- $list = model('v1.Order')->mediaOrderList();
- return $this->renderSuccess(compact('list'));
- }
- $this->error('请求错误!');
- }
-
-
- public function media_play_list()
- {
- if (IS_AJAX) {
- $list = model('v1.Order')->playList();
- return $this->renderSuccess(compact('list'));
- }
- $this->error('请求错误!');
- }
-
-
- public function media_order_detial()
- {
- if (IS_AJAX) {
- $list = model('v1.Order')->mediaOrderDetails();
- return $this->renderSuccess(compact('list'));
- }
- $this->error('请求错误!');
- }
-
-
- public function HandleUserLevelAction()
- {
- if (IS_AJAX) {
-
- $param = input('param.');
-
-
- $param['users_id'] = intval($this->users_id);
- $param['type_id'] = !empty($param['type_id']) ? intval($param['type_id']) : 0;
-
- $v1ShopModel = model('v1.Shop');
-
- $action = !empty($param['action']) ? strval($param['action']) : '';
- if ('upgrade_level' == $action) {
-
- $v1ShopModel->upgradeUserLevel($param);
- } else if ('upgrade_level_pay' == $action) {
-
- $v1ShopModel->handleUpgradeUserLevel($param);
- }
- }
- }
-
-
- public function HandleBuyMediaAction()
- {
- if (IS_AJAX) {
-
- $param = input('param.');
-
-
- $param['users_id'] = intval($this->users_id);
- $param['aid'] = !empty($param['aid']) ? intval($param['aid']) : 0;
-
- $v1ShopModel = model('v1.Shop');
-
- $action = !empty($param['action']) ? strval($param['action']) : '';
- if ('media' == $action) {
-
- $v1ShopModel->buyMedia($param);
- } else if ('media_pay' == $action) {
-
- $v1ShopModel->handleBuyMedia($param);
- }
- }
- }
-
- public function verify_action()
- {
- if (IS_AJAX) {
-
- $weappInfo = model('ShopPublicHandle')->getWeappVerifyInfo();
- if (!empty($weappInfo) && 1 === intval($weappInfo['status'])) {
-
- $verifyLogic = new \app\plugins\logic\VerifyLogic($this->users);
- $verifyLogic->verifyAction($weappInfo);
- }
- }
- $this->error('请求错误!');
- }
-
-
-
- public function log_off()
- {
- $res = Db::name('users')->where('users_id',$this->users_id)->update(['is_del'=>1,'update_time'=>getTime()]);
- if ($res !== false){
- $this->success('注销成功!');
- }
- $this->error('注销失败!');
- }
-
-
-
- public function seckill_shop_buy_now()
- {
-
- if (is_dir('./weapp/Seckill/')) {
- $SeckillRow = model('Weapp')->getWeappList('Seckill');
- if (!empty($SeckillRow) && 1 != intval($SeckillRow['status'])) {
- $this->error('请先安装并启用秒杀抢购插件!');
- }
- } else {
- $this->error('请先安装并启用秒杀抢购插件!');
- }
-
- if (IS_AJAX_POST) {
- $post = input('post.');
-
- if (empty($post['product_num']) || 0 > $post['product_num']) $this->error('请输入数量');
-
-
- $post['users_id'] = $this->users_id;
-
-
- $WeappSeckillModel = model('v1.WeappSeckill');
-
-
- $WeappSeckillModel->IsSaledOut($post);
-
-
- $WeappSeckillModel->LimitBuy($post,$this->users);
-
-
- $WeappSeckillModel->ShopBuyNow($post);
- }
- }
-
-
-
- public function seckill_shop_product_buy()
- {
-
- if (is_dir('./weapp/Seckill/')) {
- $SeckillRow = model('Weapp')->getWeappList('Seckill');
- if (!empty($SeckillRow) && 1 != intval($SeckillRow['status'])) {
- $this->error('请先安装并启用秒杀抢购插件!');
- }
- } else {
- $this->error('请先安装并启用秒杀抢购插件!');
- }
-
- if (IS_AJAX_POST) {
-
- $querystr = input('param.querystr/s');
- if (empty($querystr)) $this->error('无效链接!');
-
-
- $ShopModel = model('v1.WeappSeckill');
-
-
- $ShopModel->GetProductData($querystr,$this->users);
- }
- }
-
-
-
- public function seckill_shop_order_pay()
- {
-
- if (is_dir('./weapp/Seckill/')) {
- $SeckillRow = model('Weapp')->getWeappList('Seckill');
- if (!empty($SeckillRow) && 1 != intval($SeckillRow['status'])) {
- $this->error('请先安装并启用秒杀抢购插件!');
- }
- } else {
- $this->error('请先安装并启用秒杀抢购插件!');
- }
-
- if (IS_AJAX_POST) {
- $post = input('post.');
- $post['action'] = !empty($post['action']) ? $post['action'] : 'CreatePay';
-
-
- $post['users_id'] = $this->users_id;
- $post['openid'] = Db::name('wx_users')->where('users_id', $this->users_id)->getField('openid');
-
-
- $ShopModel = model('v1.WeappSeckill');
-
-
- if ('DirectPay' == $post['action']) {
-
- $ShopModel->OrderDirectPay($post);
- } else if ('CreatePay' == $post['action']) {
-
- if (empty($post['querystr'])) $this->error('无效链接!');
-
-
- $ShopModel->ShopOrderPay($post, $this->users);
- }
- }
- }
-
- }
|