王大坤 2 years ago
parent
commit
42eb47716c
100 changed files with 6414 additions and 1521 deletions
  1. BIN
      .DS_Store
  2. BIN
      app/.DS_Store
  3. BIN
      app/controller/.DS_Store
  4. 0 1
      app/controller/admin/Console.php
  5. BIN
      app/controller/api/.DS_Store
  6. 401 686
      app/controller/api/Ai.php
  7. 101 0
      app/controller/api/BaiduAi.php
  8. 21 3
      app/controller/api/Commission.php
  9. 5 1
      app/controller/api/Common.php
  10. 340 0
      app/controller/api/Digit.php
  11. 90 0
      app/controller/api/ErnieBotTurbo.php
  12. 0 0
      app/controller/api/Gallery.php
  13. 555 559
      app/controller/api/Pay.php
  14. 3 0
      app/controller/api/User.php
  15. 1 1
      app/controller/api/ds.json
  16. 1 1
      app/controller/api/ds2.json
  17. 10 0
      app/model/AudioList.php
  18. 18 0
      app/model/BackConfig.php
  19. 10 0
      app/model/BackList.php
  20. 10 0
      app/model/DigitUser.php
  21. 10 0
      app/model/RoleList.php
  22. 18 0
      app/model/TaskList.php
  23. 11 3
      app/model/commission/Team.php
  24. 0 1
      app/service/Bill.php
  25. 0 0
      app/service/Chatgpt.php
  26. 0 1
      app/service/Member.php
  27. 1 249
      app/service/api/Ins.php
  28. 4 2
      app/service/api/User.php
  29. BIN
      app/service/service_88szm2.tar.gz
  30. 18 0
      app/validate/DigitValidate.php
  31. 72 0
      config.php
  32. 5 5
      config/config.php
  33. BIN
      extend/.DS_Store
  34. 2 2
      extend/auth/AuthInfo.php
  35. 0 0
      extend/auth/Authorization.php
  36. 0 0
      extend/auth/Authorization.zip
  37. 1 1
      extend/baiduai/lib/75f788afb0bb2f084e4c5137eaaf8628
  38. 1 1
      extend/baiduai/lib/ca8bbcf6b966253d94b000f201de4b28
  39. 1 1
      extend/baiduai/lib/fc49e89977addb437669673eea215c11
  40. 3 3
      extend/laytp/library/UploadDomain.php
  41. 211 0
      framework/bootstrap.inc.php
  42. BIN
      framework/builtin/basic/icon.jpg
  43. 1 0
      framework/builtin/basic/index.html
  44. BIN
      framework/builtin/basic/preview.jpg
  45. 22 0
      framework/builtin/basic/processor.php
  46. BIN
      framework/builtin/chats/icon.jpg
  47. 1 0
      framework/builtin/chats/index.html
  48. 9 0
      framework/builtin/chats/module.php
  49. BIN
      framework/builtin/chats/preview.jpg
  50. 67 0
      framework/builtin/chats/processor.php
  51. 1 0
      framework/builtin/core/index.html
  52. 403 0
      framework/builtin/core/module.php
  53. 199 0
      framework/builtin/core/processor.php
  54. 156 0
      framework/builtin/core/receiver.php
  55. 282 0
      framework/builtin/core/site.php
  56. 844 0
      framework/builtin/core/template/display.html
  57. 88 0
      framework/builtin/core/template/mobile/detail.html
  58. 91 0
      framework/builtin/core/template/mobile/pay.html
  59. 60 0
      framework/builtin/core/wxapp.php
  60. 43 0
      framework/builtin/cover/processor.php
  61. BIN
      framework/builtin/custom/icon.jpg
  62. 1 0
      framework/builtin/custom/index.html
  63. BIN
      framework/builtin/custom/preview.jpg
  64. 37 0
      framework/builtin/custom/processor.php
  65. 82 0
      framework/builtin/custom/site.php
  66. 172 0
      framework/builtin/custom/template/chatlog.html
  67. 32 0
      framework/builtin/default/processor.php
  68. BIN
      framework/builtin/images/icon.jpg
  69. BIN
      framework/builtin/images/preview.jpg
  70. 18 0
      framework/builtin/images/processor.php
  71. 1 0
      framework/builtin/model.php
  72. BIN
      framework/builtin/music/icon.jpg
  73. BIN
      framework/builtin/music/preview.jpg
  74. 23 0
      framework/builtin/music/processor.php
  75. BIN
      framework/builtin/news/icon.jpg
  76. BIN
      framework/builtin/news/preview.jpg
  77. 60 0
      framework/builtin/news/processor.php
  78. 26 0
      framework/builtin/news/site.php
  79. 88 0
      framework/builtin/news/template/mobile/detail.html
  80. BIN
      framework/builtin/paycenter/icon.jpg
  81. 25 0
      framework/builtin/paycenter/inc/mobile/cardconsume.inc.php
  82. 13 0
      framework/builtin/paycenter/inc/mobile/more.inc.php
  83. 77 0
      framework/builtin/paycenter/inc/mobile/scanpay.inc.php
  84. 1 0
      framework/builtin/paycenter/inc/model.php
  85. 73 0
      framework/builtin/paycenter/module.php
  86. BIN
      framework/builtin/paycenter/preview.jpg
  87. 64 0
      framework/builtin/paycenter/processor.php
  88. 271 0
      framework/builtin/paycenter/site.php
  89. 148 0
      framework/builtin/paycenter/template/display.html
  90. 39 0
      framework/builtin/paycenter/template/mobile/cardconsume.html
  91. 101 0
      framework/builtin/paycenter/template/mobile/consume.html
  92. 74 0
      framework/builtin/paycenter/template/mobile/home.html
  93. 46 0
      framework/builtin/paycenter/template/mobile/login.html
  94. 28 0
      framework/builtin/paycenter/template/mobile/more.html
  95. 30 0
      framework/builtin/paycenter/template/mobile/nav.html
  96. 53 0
      framework/builtin/paycenter/template/mobile/order.html
  97. 25 0
      framework/builtin/paycenter/template/mobile/paydetail.html
  98. 215 0
      framework/builtin/paycenter/template/mobile/scanpay.html
  99. 43 0
      framework/builtin/paycenter/template/mobile/selfpay.html
  100. 357 0
      framework/builtin/recharge/site.php

BIN
.DS_Store


BIN
app/.DS_Store


BIN
app/controller/.DS_Store


File diff suppressed because it is too large
+ 0 - 1
app/controller/admin/Console.php


BIN
app/controller/api/.DS_Store


File diff suppressed because it is too large
+ 401 - 686
app/controller/api/Ai.php


+ 101 - 0
app/controller/api/BaiduAi.php

xqd
@@ -0,0 +1,101 @@
+<?php
+
+namespace app\controller\api;
+
+use laytp\controller\Api;
+use think\App;
+
+class BaiduAi extends Api
+{
+    public $noNeedLogin = ['chatBaidu'];
+    public function __construct(App $app)
+    {
+        parent::__construct($app);
+        header("Access-Control-Allow-Origin: *");
+        header("Content-Type: text/event-stream");
+        header("X-Accel-Buffering: no");
+        set_time_limit(0);
+        session_start();
+    }
+
+    public function chatBaidu($context){
+        $responsedata = "";
+        $postData = array(
+            'messages' => [],
+            'stream' => true
+        );
+        if (!empty($context)) {
+            $context = array_slice($context, -5);
+            foreach ($context as $message) {
+                $postData['messages'][] = ['role' => 'user', 'content' => $message[0]];
+                $postData['messages'][] = ['role' => 'assistant', 'content' => $message[1]];
+            }
+        }
+        $postData['messages'][] = ['role' => 'user', 'content' => $_POST['message']];
+        $accessToken = $this->getAccessToken();
+        $postData = $_SESSION['data'];
+        $ch = curl_init();
+        curl_setopt_array($ch, array(
+            CURLOPT_URL => "https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/eb-instant?access_token=".$accessToken,
+            CURLOPT_RETURNTRANSFER => true,
+            CURLOPT_POST => true,
+            CURLOPT_POSTFIELDS => $postData,
+            CURLOPT_HTTPHEADER => array(
+                'Content-Type: application/json',
+                'Content-Length: ' . strlen($postData)
+            ),
+            CURLOPT_WRITEFUNCTION => function ($ch, $data) {
+                global $responsedata;
+                $complete = json_decode($data);
+                if (isset($complete->error_code)) {
+                    $error = array(
+                        'id' => $complete->id,
+                        'error_code' => $complete->error_code,
+                        'error_msg' => $complete->error_msg
+                    );
+                    echo json_encode($error);
+                    flush();
+                    $responsedata = $data;
+                } else {
+                    echo $data;
+                    $responsedata .= $data;
+                    flush();
+                }
+                return strlen($data);
+            }
+        ));
+        curl_exec($ch);
+        curl_close($ch);
+        $responsearr = explode("}\n\ndata: {", $responsedata);
+        $answer = "";
+        foreach ($responsearr as $msg) {
+            $contentarr = json_decode("{" . trim($msg) . "}", true);
+            if (isset($contentarr['results'])) {
+                $results = $contentarr['results'];
+                foreach ($results as $result) {
+                    if (isset($result['result'])) {
+                        $answer .= $result['result'] . "\n";
+                    }
+                }
+            }
+        }
+    }
+    private function getAccessToken(){
+        $curl = curl_init();
+        $postData = array(
+            'grant_type' => 'client_credentials',
+            'client_id' => "biAmXmmAbUX4O4dP1YRL3LuX",
+            'client_secret' => "dhTZSa083FfhIsSPahGsroVF5yEPpkHw"
+        );
+        curl_setopt_array($curl, array(
+            CURLOPT_URL => 'https://aip.baidubce.com/oauth/2.0/token',
+            CURLOPT_CUSTOMREQUEST => 'POST',
+            CURLOPT_RETURNTRANSFER => true,
+            CURLOPT_POSTFIELDS => http_build_query($postData)
+        ));
+        $response = curl_exec($curl);
+        curl_close($curl);
+        $rtn = json_decode($response);
+        return $rtn->access_token;
+    }
+}

+ 21 - 3
app/controller/api/Commission.php

xqd
@@ -91,11 +91,29 @@ class Commission extends Api
         $limit = $this->request->param('limit', 10);
         $level = $this->request->param('level', 1);
         if($level == 1){
-            $data  = $this->model->where($where)->with(['userinfo'])->order($order)->paginate($limit)->toArray();
+            $data  = $this->model->where($where)->with(['userinfo','payMoney'])->withCount(['question','gallery'])->order($order)->paginate($limit)->each(function ($item){
+                $item->payTotal = 0;
+                foreach ($item->payMoney ?? [] as $value){
+                    $item->payTotal += $value->pay_price;
+                }
+                unset($item->payMoney);
+            })->toArray();
         }elseif($level == 2){
-            $data  = $this->model->where(['gid'=>$loginUserInfo['id'],'uniacid'=>$_GPC['uniacid']])->with(['userinfo'])->paginate($limit)->toArray();
+            $data  = $this->model->where(['gid'=>$loginUserInfo['id'],'uniacid'=>$_GPC['uniacid']])->with(['userinfo','payMoney'])->withCount(['question','gallery'])->paginate($limit)->each(function ($item){
+                $item->payTotal = 0;
+                foreach ($item->payMoney ?? [] as $value){
+                    $item->payTotal += $value->pay_price;
+                }
+                unset($item->payMoney);
+            })->toArray();
         }elseif($level == 3){
-            $data  = $this->model->where(['gfid'=>$loginUserInfo['id'],'uniacid'=>$_GPC['uniacid']])->with(['userinfo'])->paginate($limit)->toArray();
+            $data  = $this->model->where(['gfid'=>$loginUserInfo['id'],'uniacid'=>$_GPC['uniacid']])->with(['userinfo','payMoney'])->withCount(['question','gallery'])->paginate($limit)->each(function ($item){
+                $item->payTotal = 0;
+                foreach ($item->payMoney ?? [] as $value){
+                    $item->payTotal += $value->pay_price;
+                }
+                unset($item->payMoney);
+            })->toArray();
         }
         if(!$data){
             return $this->error('数据获取失败');

+ 5 - 1
app/controller/api/Common.php

xqd xqd
@@ -5,6 +5,7 @@ namespace app\controller\api;
 use app\service\ConfServiceFacade;
 use laytp\library\Random;
 use laytp\library\UploadDomain;
+use plugin\ali_oss\service\Oss;
 use plugin\qiniu_kodo\service\Kodo;
 use laytp\library\Tree;
 use laytp\controller\Api;
@@ -69,17 +70,20 @@ class Common extends Api
     {
         global $_GPC;
         try {
+
             $uploadType = $this->request->param('upload_type', 'local');
             if (!in_array($uploadType, ['local', 'ali-oss', 'qiniu-kodo'])) {
                 return $this->error($uploadType . '上传方式未定义');
             }
+
             $file = $this->request->file('file'); // 获取上传的文件
+
             if (!$file) {
                 return $this->error('上传失败,请选择需要上传的文件');
             }
             $fileExt = strtolower($file->getOriginalExtension());
             $uploadDomain = new UploadDomain();
-            if (!$uploadDomain->check($file->getOriginalName(), $file->getSize(), $fileExt, $file->getMime())) {
+            if (!$uploadDomain->check($file->getOriginalName(), $file->getSize(), $fileExt,true)) {
                 return $this->error($uploadDomain->getError());
             }
             $saveName = date("Ymd") . "/" . md5(uniqid(mt_rand())) . ".{$fileExt}";

+ 340 - 0
app/controller/api/Digit.php

xqd
@@ -0,0 +1,340 @@
+<?php
+
+namespace app\controller\api;
+
+use app\model\AudioList;
+use app\model\BackConfig;
+use app\model\BackList;
+use app\model\DigitUser;
+use app\model\RoleList;
+use app\model\TaskList;
+use app\validate\DigitValidate;
+use laytp\controller\Api;
+use think\App;
+use think\Exception;
+use think\Request;
+
+/**
+ * AI相关
+ * @ApiWeigh (90)
+ */
+class Digit extends Api
+{
+    public $user;
+
+    public function __construct(Request $request, App $app)
+    {
+        parent::__construct($app);
+        $token = $request->header('Authorization');
+        $this->user = DigitUser::where('token', $token)->where('expire_time', '>', time())->find();
+    }
+
+    public $noNeedLogin = [
+        "list",
+        "addDigit",
+        'deleteDigit',
+        'draftList',
+        'getRoleList',
+        'getBackList',
+        'getAudioList',
+        'saveVideoPath',
+        'register',
+        'login',
+        'getUserInfo',
+        'userUpdate',
+        'getBackImageByRole'
+    ];
+
+    /**
+     * 验证登陆
+     *
+     * @return string|\think\response\Json
+     */
+//    private function checkLogin(){
+//        if (!$this->user){
+//            return $this->error('登陆信息已过期');
+//        }
+//        return '';
+//    }
+    /**
+     * 获取用户信息
+     *
+     * @return false|string|\think\response\Json
+     */
+    public function getUserInfo()
+    {
+        if (!$this->user) {
+            abort(401, '登陆信息已过期');
+        }
+        return $this->success($this->user);
+    }
+
+    /**
+     * 更新用户信息
+     *
+     * @return false|string|\think\response\Json
+     */
+    public function userUpdate()
+    {
+        $params = $this->request->param();
+        $this->user->save($params);
+        return $this->success();
+    }
+
+    // 数字人列表
+    public function list()
+    {
+        if (!$this->user) {
+            abort(401, '登陆信息已过期');
+        }
+        $digit = TaskList::field('id,state,url,cover,name')
+            ->where('is_draft', 0)
+            ->where('user_id', $this->user->id ?? 0)
+            ->order('id desc')
+            ->select();
+        return $this->success('数据获取成功', $digit);
+    }
+
+    /**
+     *
+     * 获取数字人草稿
+     * @return false|string|\think\response\Json
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function draftList()
+    {
+        if (!$this->user) {
+            abort(401, '登陆信息已过期');
+        }
+        $digit = TaskList::with(['backs', 'roles', 'audios'])->field('id,state,url,cover,name,stage,content,(audio + 1) as audio,(back + 1) as back,(role + 1) as role,audio_url')
+            ->where('is_draft', 1)
+            ->where('user_id', $this->user->id ?? 0)
+            ->select();
+        return $this->success('数据获取成功', $digit);
+    }
+
+    /**
+     * 新增任务
+     *
+     * @return false|string|\think\response\Json
+     */
+    public function addDigit($name, $content = '', $role, $back, $audio = 0, $stage = 1.1, $is_draft = 0, $audio_url = '')
+    {
+        if (!$this->user) {
+            abort(401, '登陆信息已过期');
+        }
+        $audio_file_name = explode('/', $audio_url);
+        $type = 0;
+        $validate = new DigitValidate();
+        $data = [
+            'name' => $name,
+            'type' => empty($audio_url) ? $type : 2,
+            'content' => $content,
+            'role' => $role,
+            'back' => $back,
+            'audio' => $audio,
+            'stage' => $stage,
+            'user_id' => $this->user->id ?? 0,
+            'audio_file_name' => empty($audio_url) ? null : end($audio_file_name),
+            'audio_url' => empty($audio_url) ? null : $audio_url
+        ];
+        if (!$validate->check($data)) {
+            return $this->error($validate->getError());
+        }
+        if (mb_strlen($content) < 10) {
+            return $this->error('内容过短,请输入至少10个文字;');
+        }
+        $data = array_merge($data, ['created_at' => date('Y-m-d H:i:s'), 'is_draft' => $is_draft]);
+        $digit = TaskList::create($data);
+        return $this->success('创建成功');
+    }
+
+    /**
+     *
+     * 删除数字人
+     * @param $id
+     * @return false|string|\think\response\Json
+     */
+    public function deleteDigit($id)
+    {
+        if (!$this->user) {
+            abort(401, '登陆信息已过期');
+        }
+        $delete = TaskList::where('id', $id)->where('user_id', $this->user->id ?? 0)->delete();
+        if ($delete) {
+            return $this->success('删除成功');
+        } else {
+            return $this->error('删除失败');
+        }
+    }
+
+    /**
+     * 获取角色列表
+     *
+     * @return false|string|\think\response\Json
+     */
+    public function getRoleList()
+    {
+        return $this->success(RoleList::field('id,url,name,proportion')->select());
+    }
+
+    /**
+     * 获取背景列表
+     *
+     * @return false|string|\think\response\Json
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function getBackList()
+    {
+        return $this->success(BackList::field('id,url,scale')->select());
+    }
+
+    /**
+     * 获取声音列表
+     *
+     * @return false|string|\think\response\Json
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function getAudioList()
+    {
+        return $this->success(AudioList::field('id,url,name,title')->select());
+    }
+
+
+    protected function getSslPage($url)
+    {
+        $ch = curl_init();
+        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
+        curl_setopt($ch, CURLOPT_HEADER, false);
+        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
+        curl_setopt($ch, CURLOPT_URL, $url);
+        curl_setopt($ch, CURLOPT_REFERER, $url);
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
+        $result = curl_exec($ch);
+        curl_close($ch);
+        return $result;
+    }
+
+
+    public function saveVideoPath($videoUrl, $id = 0, $cover = '')
+    {
+        try {
+            $videoContent = file_get_contents($videoUrl);
+            $coverContent = file_get_contents($cover);
+            $videoDir = $_SERVER['DOCUMENT_ROOT'] . '/static/video/' . date('Ymd') . '/';
+            $imageDir = $_SERVER['DOCUMENT_ROOT'] . '/static/images/' . date('Ymd') . '/';
+            $path = uniqid() . time() . '_video.mp4';
+            $pathCover = uniqid() . time() . '_images.jpg';
+            $host = $_SERVER['HTTP_HOST'] . '/static/video/' . date('Ymd') . '/';
+            $hostCover = $_SERVER['HTTP_HOST'] . '/static/images/' . date('Ymd') . '/';
+            $localFilePath = $videoDir . $path;
+            $localFilePathCover = $imageDir . $pathCover;
+            if (!is_dir($videoDir)) {
+                mkdir($videoDir, 0777, true);
+            }
+            if (!is_dir($imageDir)) {
+                mkdir($imageDir, 0777, true);
+            }
+            if ($videoContent !== false) {
+                $saved = file_put_contents($localFilePath, $videoContent);
+                $savedImages = file_put_contents($localFilePathCover, $coverContent);
+                if ($saved !== false && $savedImages !== false) {
+                    $url = 'https://' . $host . $path;
+                    $cover = 'https://' . $hostCover . $pathCover;
+                    TaskList::where('id', $id)->update([
+                        'url' => $url,
+                        'state' => 1,
+                        'cover' => $cover,
+                        'build_at' => time()
+                    ]);
+                    return $this->success('保存成功', ['url' => $url]);
+                } else {
+                    return $this->error('保存失败');
+                }
+            } else {
+                return $this->error('保存失败#');
+            }
+        } catch (\Exception$exception) {
+            var_dump($exception->getMessage());
+        }
+        return 'xxxx';
+
+    }
+
+    /**
+     * 帐号登陆
+     *
+     * @param Request $request
+     * @return false|string|\think\response\Json
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function login(Request $request)
+    {
+        $account = $request->post('account', '');
+        $password = $request->post('password', '');
+        try {
+            $user = DigitUser::where('account', $account)->find();
+        } catch (\Exception $e) {
+            var_dump($e->getMessage());
+        }
+
+        if (!$user) {
+            return $this->error('帐号不存在');
+        }
+        if ($user->password != md5($password)) {
+            return $this->error('密码错误');
+        }
+        $token = md5($user->account . uniqid());
+        $user->token = $token;
+        $user->updated_at = date('Y-m-d H:i:s');
+        $user->save();
+        return $this->success('登陆成功', ['token' => $token]);
+    }
+
+    /**
+     * 注册成功
+     *
+     * @param Request $request
+     * @return false|string|\think\response\Json
+     */
+    public function register(Request $request)
+    {
+        $account = $request->post('account', '');
+        if (empty($account)) {
+            return $this->error('请输入帐号');
+        }
+        $password = $request->post('password', '');
+        $isUser = DigitUser::where('account', $account)->find();
+        if ($isUser) {
+            return $this->error('帐号已注册');
+        }
+        $user = DigitUser::create([
+            'account' => $account,
+            'password' => md5($password)
+        ]);
+        if (!$user) {
+            return $this->error('注册失败');
+        }
+        return $this->success('注册成功');
+    }
+
+    /**
+     * 获取合成背景
+     *
+     * @param $roleId
+     * @param $backId
+     * @return false|string|\think\response\Json
+     */
+    public function getBackImageByRole($roleId = 1,$backId = 1){
+        $backImage = BackConfig::where(['role' => $roleId,'back' => $backId])->value('url');
+        return $this->success('获取成功',$backImage);
+    }
+}

+ 90 - 0
app/controller/api/ErnieBotTurbo.php

xqd
@@ -0,0 +1,90 @@
+<?php
+
+namespace app\controller\api;
+
+use app\service\api\ImageCensorServiceFacade;
+use app\service\api\InsServiceFacade;
+use app\service\api\UserServiceFacade;
+use app\service\ConfServiceFacade;
+use app\service\MemberServiceFacade;
+use laytp\controller\Api;
+
+class ErnieBotTurbo extends Api
+{
+
+    public $noNeedLogin = [
+        "test",
+    ];
+
+    const API_KEY = "biAmXmmAbUX4O4dP1YRL3LuX";
+    const SECRET_KEY = "dhTZSa083FfhIsSPahGsroVF5yEPpkHw";
+    public function test(){
+        $this->run(['messages' => [["role" => "user","content"=>"写一篇2000字的文章,关于我的母亲"]],"stream" => true]); //,
+    }
+
+    /**
+     * 运行
+     * @param array $message
+     * @return bool|string
+     */
+    public function run(array $message) {
+        $i = 0;
+//        ob_start();
+        $callback = function ($ch, $data) use(&$stdout,&$i){
+            $i++;
+            $jsonString = substr($data, 6, -1);
+            $complete = @json_decode($jsonString, true);
+            if ($complete['is_end']){
+                header('Connection: close');
+                // 刷新输出缓冲区并关闭输出缓冲
+                ob_end_flush();
+                // 结束当前脚本
+                exit;
+            }
+            echo $complete['result'];
+            ob_flush();
+            flush();
+            return strlen($data);
+        };
+        $ch = curl_init();
+        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
+        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
+        curl_setopt($ch, CURLOPT_URL, "https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/eb-instant?access_token={$this->getAccessToken()}");
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+        curl_setopt($ch, CURLOPT_HTTPHEADER,  array(
+            'Content-Type: application/json'
+        ));
+        curl_setopt($ch, CURLOPT_POST, true);
+        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($message,256));
+        curl_setopt($ch, CURLOPT_WRITEFUNCTION, $callback);
+        register_shutdown_function(function() use ($ch, $stdout) {
+            curl_close($ch);
+            fclose($stdout);
+        });
+
+        curl_exec($ch);
+    }
+
+    /**
+     * 使用 AK,SK 生成鉴权签名(Access Token)
+     * @return string 鉴权签名信息(Access Token)
+     */
+    private function getAccessToken(){
+        $curl = curl_init();
+        $postData = array(
+            'grant_type' => 'client_credentials',
+            'client_id' => self::API_KEY,
+            'client_secret' => self::SECRET_KEY
+        );
+        curl_setopt_array($curl, array(
+            CURLOPT_URL => 'https://aip.baidubce.com/oauth/2.0/token',
+            CURLOPT_CUSTOMREQUEST => 'POST',
+            CURLOPT_RETURNTRANSFER => true,
+            CURLOPT_POSTFIELDS => http_build_query($postData)
+        ));
+        $response = curl_exec($curl);
+        curl_close($curl);
+        $rtn = json_decode($response);
+        return $rtn->access_token;
+    }
+}

File diff suppressed because it is too large
+ 0 - 0
app/controller/api/Gallery.php


+ 555 - 559
app/controller/api/Pay.php

xqd
@@ -1,559 +1,555 @@
-<?php
-
-namespace app\controller\api;
-use app\service\api\UserServiceFacade;
-// use app\service\api\MiniappServiceFacade;
-use app\service\api\PayServiceFacade;
-use app\service\api\HupijiaopayServiceFacade;
-use app\service\ConfServiceFacade;
-use app\service\BillServiceFacade;
-// use app\service\admin\CapitalFlowServiceFacade;
-use laytp\controller\Api;
-use think\facade\Request;
-// use think\facade\Queue;
-use app\service\MessageSystemServiceFacade;
-use think\facade\Queue;
-
-/**
- * 获取系统配置
- */
-class Pay extends Api{
-
-  protected function _initialize()
-  {
-      $this->model = new \app\model\Order();
-  }
-
-  // 无需登录的接口,*表示全部
-  public $noNeedLogin = ['notify','test','notifySettle','notifyHupijiao'];
-
-  public function hupijiaopay(){
-      global $_GPC;
-      $post = $this->request->post();
-      $isCommission = $this->request->post('is_commission',0);
-      $returnUrl = $this->request->post('return_url','');
-      $callbackUrl = $this->request->post('callback_url','');
-      $platform = $this->request->header('platform');
-      // 获得订单信息
-      if ($isCommission ==1) {
-          $notify = IS_R==1?request()->domain() . SURL . '/api.pay/notifySettleHupijiao':request()->domain() . SURL . '/index.php/api.pay/notifySettleHupijiao';
-          $pay_price = \app\model\commission\Settle::where(['order_number'=>$post['order_number']])->value('pay_price');
-      } else {
-          $notify = IS_R==1?request()->domain() . SURL . '/api.pay/notifyHupijiao':request()->domain() . SURL . '/index.php/api.pay/notifyHupijiao';
-          $pay_price = \app\model\Order::where(['order_number'=>$post['order_number']])->value('pay_price');
-      }
-      if(!$pay_price){
-        return $this->error('获取订单数据失败');
-      }
-
-      $data =[
-          'version' => 1.1,
-          'trade_order_id'=>$post['order_number'],
-          'total_fee'=>$pay_price,
-          'title'=>'充值',
-          'time'=>time(),
-          'notify_url'=>$notify,
-          'return_url' => $returnUrl,
-          'callback_url'=>$callbackUrl,
-          'type'=>'WAP',
-          'wap_name'=>'支付'
-      ];
-      $res = HupijiaopayServiceFacade::pay($data);
-      return $this->success('获取结果', $res);
-  }
-
-  public function prepay(){
-      global $_GPC;
-    $post = $this->request->post();
-    $platform = $this->request->post('platform');
-    $isCommission = $this->request->post('is_commission',0);
-
-    // 获得订单信息
-    if ($isCommission ==1) {
-        $notify = IS_R==1?request()->domain() . SURL . '/api.pay/notifySettle':request()->domain() . SURL . '/index.php/api.pay/notifySettle';
-        $pay_price = \app\model\commission\Settle::where(['order_number'=>$post['order_number']])->value('pay_price');
-    } else {
-        $notify = IS_R==1?request()->domain() . SURL . '/api.pay/notify':request()->domain() . SURL . '/index.php/api.pay/notify';
-        $pay_price = \app\model\Order::where(['order_number'=>$post['order_number']])->value('pay_price');
-    }
-    if(!$pay_price){
-      return $this->error('获取订单数据失败');
-    }
-    // print_r(request()->domain() . SURL . '/index.php/api.pay/notify');
-    $app  = PayServiceFacade::option($platform=='wxOfficialAccount'?'wechat':'miniapp');
-    $loginUserInfo = UserServiceFacade::getUserInfo();
-    // print_r($loginUserInfo);
-    $result = $app->order->unify([
-        'body' => '充值',
-        'out_trade_no' => $post['order_number'],
-        'total_fee' => $pay_price * 100,
-        'notify_url' => $notify, // 支付结果通知网址,如果不设置则会使用配置里的默认地址
-        'trade_type' => 'JSAPI', // 请对应换成你的支付方式对应的值类型
-        'openid' => $platform=='wxOfficialAccount'?$loginUserInfo['openid_wechat']:$loginUserInfo['openid_miniapp'],
-    ]);
-    $jssdk = $app->jssdk;
-    if($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS'){
-      $config = $jssdk->bridgeConfig($result['prepay_id'], false);
-      return $this->success('获取结果', $config);
-    }
-    return $this->error('获取失败,'.json_encode($result,320));
-  }
-
-  public function hupijiao()
-  {
-      global $_GPC;
-  }
-
-  public function notify(){
-    global $_GPC;
-    // $app = PayServiceFacade::option();
-    $notifiedData = file_get_contents('php://input');
-    $xmlObj = simplexml_load_string($notifiedData, 'SimpleXMLElement', LIBXML_NOCDATA);
-    $xmlObj = json_decode(json_encode($xmlObj), true);
-    // 库里查
-    $order = $this->model->where('order_number','=',$xmlObj['out_trade_no'])->find();
-    // 如果订单不存在 或者 订单已经支付过了
-    if(!$order || $order['paid'] == 1){
-      return true;  //已经处理 或该笔订单库里已经支付,微信你请勿再通知
-    }
-    if ($xmlObj['return_code'] === 'SUCCESS') { // return_code 表示通信状态,不代表支付状态
-        // 用户是否支付成功
-        if ($xmlObj['result_code'] === 'SUCCESS') {
-          // 用户支付成功
-          $_GPC['uniacid'] = $order['uniacid'];
-          $updateRes  = $this->model->where('order_number', '=', $xmlObj['out_trade_no'])->update(['paid'=>1, 'pay_time' => time()]);
-          $memberInfo = \app\model\Member::find($order['link_id']);
-          $this->setMember($order,$memberInfo);
-
-         // 分销
-         $this->setCommission($order,$memberInfo);
-
-          // $title = '下单支付成功通知';
-          // $content = '您的订单已支付,订单编号'.$xmlObj['out_trade_no'].',价格:¥'.$order['pay_price'];
-          // $jobQueueName ='wike_oddjob';
-          // $queueData =[
-          //     'uid' => $order['uid'],
-          //     'title'=>$title,
-          //     'content'=>$content,
-          //     'order_number'=>$xmlObj['out_trade_no'],
-          //     'pay_price'=>$order['pay_price'],
-          //     'status'=>'已支付',
-          //     'remark'=>'订单价格:'.$order['pay_price'],
-          //     'uniacid' => $order['uniacid']
-          // ];
-          // MessageSystemServiceFacade::Unified($order['uid'],$title,$content);
-          // $conf = ConfServiceFacade::groupGet('system.notification');
-          // if($conf['subscribe_status'] == 1){
-          //     Queue::later(3, 'app\jobs\SubscribeMessageJob@pay_suc', $queueData, $jobQueueName);
-          // }
-
-          // Queue::later(86400, 'app\jobs\SubscribeMessageJob@recommend', $queueData, $jobQueueName);
-          // Queue::later(432000, 'app\jobs\SubscribeMessageJob@new_video', $queueData, $jobQueueName);
-          if (!$updateRes) return false;
-        } elseif ($xmlObj['result_code'] === 'FAIL') {
-          // 用户支付失败
-          return false;
-        }
-    } else {
-        return false;
-    }
-    return true;
-    // file_put_contents(__DIR__ . '/ds.json', json_encode($xmlObj));
-  }
-
-  public function notifySettle(){
-    global $_GPC;
-    $modelSettle = new \app\model\commission\Settle();
-    $modelTeam =new \app\model\commission\Team();
-    $modelIncome =new \app\model\commission\Income();
-    $modelUser =new \app\model\commission\User();
-    // $app = PayServiceFacade::option();
-    $notifiedData = file_get_contents('php://input');
-    $xmlObj = simplexml_load_string($notifiedData, 'SimpleXMLElement', LIBXML_NOCDATA);
-    $xmlObj = json_decode(json_encode($xmlObj), true);
-    // 库里查
-    $order = $modelSettle->where('order_number','=',$xmlObj['out_trade_no'])->find();
-    // file_put_contents(__DIR__ . '/ds.json', json_encode($order));
-    // 如果订单不存在 或者 订单已经支付过了
-    if(!$order || $order['paid'] == 1){
-      return true;  //已经处理 或该笔订单库里已经支付,微信你请勿再通知
-    }
-    if ($xmlObj['return_code'] === 'SUCCESS') { // return_code 表示通信状态,不代表支付状态
-        // 用户是否支付成功
-        if ($xmlObj['result_code'] === 'SUCCESS') {
-          // 用户支付成功
-
-          $_GPC['uniacid'] = $order['uniacid'];
-          $updateRes  =$modelSettle->where('order_number', '=', $xmlObj['out_trade_no'])->update(['paid'=>1, 'pay_time' => time()]);
-          $updateRes2 = $modelUser->save(['paid' => 1,'uniacid'=>$order['uniacid'],'status'=>1,'paid'=>1,'uid'=>$order['uid'],'real_name'=>$order['real_name'],'telnum'=>$order['telnum'] ]);
-
-          // 分销
-
-          $teamUserInfo = $modelTeam::where('uid','=',$order['uid'])->find();
-          $conf = ConfServiceFacade::groupGet('system.commission');
-
-          if(!empty($conf['is_commission']) && $conf['is_commission']==1 ){
-              if($conf['first'] > 0){
-                 $firstLevel = $order['pay_price'] * ($conf['first'])/100;
-              }
-              if($conf['second'] > 0){
-                 $secondLevel = $order['pay_price'] * ($conf['second'])/100;
-              }
-              if($conf['third'] > 0){
-                 $thirdLevel = $order['pay_price'] * ($conf['third'])/100;
-              }
-
-                if(!empty($teamUserInfo['pid'])){
-                      // 奖励给pid
-                      // 计算一级分销返佣
-                      $higherUserInfo = $modelUser::where('uid','=',$teamUserInfo['pid'])->find();
-                      if(!empty($higherUserInfo) && $higherUserInfo['status'] == 1){
-                          $banlance = $higherUserInfo['money'] + $firstLevel;
-                          $modelUser::where('uid','=',$teamUserInfo['pid'])->update(['money'=>$banlance]);
-                          // $a = $modelIncome->save(['money'=>$firstLevel,'uid'=>$teamUserInfo['pid'],'mark'=>'您的一级下线支付订单金额:¥'.$order['pay_price'].'购买了'.$memberInfo['title'].'套餐。您获得的佣金是:'.$conf['first'].'%返佣,¥'.$firstLevel,'uniacid'=>$_GPC['uniacid']]);
-                          $a = $modelIncome->create([
-                                 'money' => $firstLevel,
-                                 'oid' => $order['id'],
-                                 'uid' => $teamUserInfo['pid'],
-                                 'buy_uid' => $order['uid'],
-                                 'buy_price'=>$order['pay_price'],
-                                 'mark' => '您的一级下线支付订单金额:¥'.$order['pay_price'].'入驻分销商。您获得的佣金是:'.$conf['first'].'%返佣,¥'.$firstLevel,
-                                 'uniacid'=>$_GPC['uniacid'],
-                             ]);
-                      }
-                  }
-                  if(!empty($teamUserInfo['gid'])){
-                      // 奖励给gid
-                      // 计算一级分销返佣
-                      $higherUserInfo = $modelUser::where('uid','=',$teamUserInfo['gid'])->find();
-                      if(!empty($higherUserInfo) && $higherUserInfo['status'] == 1){
-                          $banlance = $higherUserInfo['money'] + $secondLevel;
-                          $modelUser::where('uid','=',$teamUserInfo['gid'])->update(['money'=>$banlance]);
-                          // $b = $modelIncome->save(['money'=>$secondLevel,'uid'=>$teamUserInfo['gid'],'mark'=>'您的二级下线支付订单金额:¥'.$order['pay_price'].'购买了'.$memberInfo['title'].'套餐。您获得的佣金是:'.$conf['second'].'%返佣,¥'.$secondLevel,'uniacid'=>$_GPC['uniacid']]);
-                          $b = $modelIncome->create([
-                                 'money' => $secondLevel,
-                                 'uid' => $teamUserInfo['gid'],
-                                 'oid' => $order['id'],
-                                 'buy_uid' => $order['uid'],
-                                 'buy_price'=>$order['pay_price'],
-                                 'mark' => '您的二级下线支付订单金额:¥'.$order['pay_price'].'入驻分销商。您获得的佣金是:'.$conf['second'].'%返佣,¥'.$secondLevel,
-                                 'uniacid'=>$_GPC['uniacid'],
-                             ]);
-                      }
-                  }
-                  if(!empty($teamUserInfo['gfid'])){
-                      // 奖励给gfid
-                      // 计算一级分销返佣
-                      $higherUserInfo = $modelUser::where('uid','=',$teamUserInfo['gfid'])->find();
-                      if(!empty($higherUserInfo) && $higherUserInfo['status'] == 1){
-                          $banlance = $higherUserInfo['money'] + $thirdLevel;
-                          $modelUser::where('uid','=',$teamUserInfo['gfid'])->update(['money'=>$banlance]);
-                          // $c = $modelIncome->save(['money'=>$thirdLevel,'uid'=>$teamUserInfo['gfid'],'mark'=>'您的三级下线支付订单金额:'.$order['pay_price'].'购买了'.$memberInfo['title'].'套餐。您获得的佣金是:'.$conf['third'].'%返佣,¥'.$secondLevel,'uniacid'=>$_GPC['uniacid']]);
-                          $c = $modelIncome->create([
-                                 'money' => $thirdLevel,
-                                 'uid' => $teamUserInfo['gfid'],
-                                 'oid' => $order['id'],
-                                 'buy_uid' => $order['uid'],
-                                 'buy_price'=>$order['pay_price'],
-                                 'mark' => '您的三级下线支付订单金额:¥'.$order['pay_price'].'入驻分销商。您获得的佣金是:'.$conf['third'].'%返佣,¥'.$thirdLevel,
-                                 'uniacid'=>$_GPC['uniacid'],
-                             ]);
-                      }
-              }
-
-          }
-          if (!$updateRes) return false;
-        } elseif ($xmlObj['result_code'] === 'FAIL') {
-          // 用户支付失败
-          return false;
-        }
-    } else {
-        return false;
-    }
-    return true;
-    // file_put_contents(__DIR__ . '/ds.json', json_encode($xmlObj));
-  }
-
-  public function notifyHupijiao()
-  {
-      global $_GPC;
-      $post = $this->request->post();
-      // file_put_contents(__DIR__ . '/notifyHupijiao.json', json_encode($post));
-      // 库里查
-      $order = $this->model->where('order_number','=',$post['trade_order_id'])->find();
-      // file_put_contents(__DIR__ . '/ds.json', json_encode($order));
-      // 如果订单不存在 或者 订单已经支付过了
-      if(!$order || $order['paid'] == 1){
-        return true;  //已经处理 或该笔订单库里已经支付,微信你请勿再通知
-      }
-      if($post['status'] === 'OD'){
-          $_GPC['uniacid'] = $order['uniacid'];
-          $updateRes  = $this->model->where('order_number', '=', $post['trade_order_id'])->update(['paid'=>1, 'pay_time' => time(),'pay_channel'=>'hupijiao']);
-          $memberInfo = \app\model\Member::find($order['link_id']);
-          $this->setMember($order,$memberInfo);
-         // 分销
-         $this->setCommission($order,$memberInfo);
-      }
-      return 'success';
-  }
-
-  public function setMember($order,$memberInfo)
-  {
-      global $_GPC;
-
-      if(!empty($memberInfo) && !empty($memberInfo['type'])){
-         if($memberInfo['type']==2){
-             $modelVipinfo =new \app\model\Vipinfo();
-             $title = '充值时长';
-             $userInfo = \app\model\User::find($order['uid']);
-             if($memberInfo['day'] === 9999){
-                 $title = $title.'(永久)';
-                 $updateRes2 = \app\model\User::where('id', '=', $order['uid'])->update(['vip_time' => 9999]);
-             }else{
-                 $title = $title.'('.$memberInfo['day'].'天)';
-                 if($userInfo['vip_time'] < time()){
-                     $balance = strtotime("+".$memberInfo['day']."days");
-                 }else{
-                     // file_put_contents(__DIR__ . '/d.json', $memberInfo['day']*24*60*60);
-                     $balance = $userInfo['vip_time'] + $memberInfo['day']*24*60*60;
-                 }
-                 $updateRes2 = \app\model\User::where('id', '=', $order['uid'])->update(['vip_time' => $balance]);
-             }
-             BillServiceFacade::record(1,$memberInfo['coin'],'pay_member',$title,$order['uid'],$order['uniacid']);
-             // 写入余量
-             $vipinfo = $modelVipinfo->where('uid',$order['uid'])->find();
-             if(empty($vipinfo)){
-                 $save =[
-                     'uid'=>$order['uid'],
-                     'gpt35_times'=>$memberInfo['gpt35_times']?$memberInfo['gpt35_times']:0,
-                     'gpt4_times'=>$memberInfo['gpt4_times']?$memberInfo['gpt4_times']:0,
-                     'sd_times'=>$memberInfo['sd_times']?$memberInfo['sd_times']:0,
-                     'mj_times'=>$memberInfo['mj_times']?$memberInfo['mj_times']:0,
-                     'gpt35_type'=>$memberInfo['gpt35_type']?$memberInfo['gpt35_type']:'time',
-                     'gpt4_type'=>$memberInfo['gpt4_type']?$memberInfo['gpt4_type']:'time',
-                     'sd_type'=>$memberInfo['sd_type']?$memberInfo['sd_type']:'time',
-                     'mj_type'=>$memberInfo['mj_type']?$memberInfo['mj_type']:'time',
-                     'order_number'=>$order['order_number'],
-                     'member_id'=>$memberInfo['id'],
-                     'uniacid'=>$_GPC['uniacid']
-                 ];
-
-                 $res = $modelVipinfo->save($save);
-                 file_put_contents(__DIR__ . '/vipinfo.json', json_encode($res));
-             }else{
-                 $updata =[
-                     // 'gpt35_times'=>$memberInfo['gpt35_times']?$memberInfo['gpt35_times']:0,
-                     // 'gpt4_times'=>$memberInfo['gpt4_times']?$memberInfo['gpt4_times']:0,
-                     // 'sd_times'=>$memberInfo['sd_times']?$memberInfo['sd_times']:0,
-                     // 'mj_times'=>$memberInfo['mj_times']?$memberInfo['mj_times']:0,
-                     'order_number'=>$order['order_number'],
-                     'member_id'=>$memberInfo['id'],
-                     'uniacid'=>$_GPC['uniacid']
-                 ];
-                 if($memberInfo['gpt35_times'] == -1){
-                     $updata['gpt35_times'] = -1;
-                 }else{
-                     if($userInfo['vip_time'] <= time()){
-                         // 过期
-                             $updata['gpt35_times'] = $memberInfo['gpt35_times'];
-                     }else{
-                         if($vipinfo['gpt35_times']==-1){
-                            $updata['gpt35_times'] = -1;
-                         }else{
-                             $updata['gpt35_times'] = $vipinfo['gpt35_times'] + $memberInfo['gpt35_times'];
-                         }
-                     }
-
-                 }
-                 if($memberInfo['gpt4_times'] == -1){
-                     $updata['gpt4_times'] = -1;
-                 }else{
-                     if($userInfo['vip_time'] <= time()){
-                         $updata['gpt4_times'] = $memberInfo['gpt4_times'];
-                     }else{
-                         if($vipinfo['gpt4_times']==-1){
-                             $updata['gpt4_times'] = -1;
-                         }else{
-                             $updata['gpt4_times'] = $vipinfo['gpt4_times'] + $memberInfo['gpt4_times'];
-                         }
-
-                     }
-                 }
-                 if($memberInfo['sd_times'] == -1){
-                     $updata['sd_times'] = -1;
-                 }else{
-                     if($userInfo['vip_time'] <= time()){
-                         $updata['sd_times'] = $memberInfo['sd_times'];
-                     }else{
-                         if($vipinfo['sd_times']==-1){
-                             $updata['sd_times'] = -1;
-                         }else{
-                             $updata['sd_times'] = $vipinfo['sd_times'] + $memberInfo['sd_times'];
-                         }
-                     }
-                 }
-                 if($memberInfo['mj_times'] == -1){
-                     $updata['mj_times'] = -1;
-                 }else{
-                     if($userInfo['vip_time'] <= time()){
-                         $updata['mj_times'] = $memberInfo['mj_times'];
-                     }else{
-                         if($vipinfo['mj_times']==-1){
-                             $updata['mj_times'] = -1;
-                         }else{
-                             $updata['mj_times'] = $vipinfo['mj_times'] + $memberInfo['mj_times'];
-                         }
-                     }
-
-                 }
-                  $modelVipinfo->where('uid',$order['uid'])
-                  ->update($updata);
-             }
-         }else{
-              $updateRes2 = \app\model\User::where('id', '=', $order['uid'])->inc('coin',$memberInfo['coin'])->update();
-              BillServiceFacade::record(1,$memberInfo['coin'],'pay_member','充值次数',$order['uid'],$order['uniacid']);
-         }
-      }
-  }
-
-  public function setCommission($order,$memberInfo)
-  {
-      global $_GPC;
-
-      $modelTeam =new \app\model\commission\Team();
-      $modelIncome =new \app\model\commission\Income();
-      $modelUser =new \app\model\commission\User();
-      $teamUserInfo = $modelTeam::where('uid','=',$order['uid'])->find();
-      $conf = ConfServiceFacade::groupGet('system.commission');
-      // 获得购买者是否是分销商
-      $buyUserInfo= $modelUser::where('uid','=',$order['uid'])->find();
-      if(!empty($conf['is_commission']) && $conf['is_commission']==1 ){
-
-          if($conf['first'] > 0){
-             $firstLevel = $order['pay_price'] * ($conf['first'])/100;
-          }
-          if($conf['second'] > 0){
-             $secondLevel = $order['pay_price'] * ($conf['second'])/100;
-          }
-          if($conf['third'] > 0){
-             $thirdLevel = $order['pay_price'] * ($conf['third'])/100;
-          }
-
-          if(!empty($conf['is_self_buy']) &&  $conf['is_self_buy'] == 1 && !empty($buyUserInfo) && $buyUserInfo['status'] == 1){
-
-              // 开启自购
-               $higherUserInfo = $modelUser::where('uid','=',$order['uid'])->find();
-               $banlance = $higherUserInfo['money'] + $firstLevel;
-               $modelUser::where('uid','=',$order['uid'])->update(['money'=>$banlance]);
-               // $a = $modelIncome->save(['money'=>$firstLevel,'uid'=>$teamUserInfo['pid'],'mark'=>'您的一级下线支付订单金额:¥'.$order['pay_price'].'购买了'.$memberInfo['title'].'套餐。您获得的佣金是:'.$conf['first'].'%返佣,¥'.$firstLevel,'uniacid'=>$_GPC['uniacid']]);
-               $a = $modelIncome->create([
-                      'money' => $firstLevel,
-                      'oid' => $order['id'],
-                      'uid' => $order['uid'],
-                      'buy_uid' => $order['uid'],
-                      'buy_price'=>$order['pay_price'],
-                      'mark' => '自购返佣:您支付订单金额:¥'.$order['pay_price'].'购买了'.$memberInfo['title'].'套餐。您获得的佣金是:'.$conf['first'].'%返佣,¥'.$firstLevel,
-                      'uniacid'=>$_GPC['uniacid'],
-                  ]);
-                  if(!empty($teamUserInfo['pid'])){
-                      // 奖励给pid
-                      // 计算一级分销返佣
-                      $higherUserInfo = $modelUser::where('uid','=',$teamUserInfo['pid'])->find();
-                      // if($higherUserInfo['status'] == 1){
-                          $banlance = $higherUserInfo['money'] + $secondLevel;
-                          $modelUser::where('uid','=',$teamUserInfo['pid'])->update(['money'=>$banlance]);
-                          // $a = $modelIncome->save(['money'=>$secondLevel,'uid'=>$teamUserInfo['pid'],'mark'=>'您的一级下线支付订单金额:¥'.$order['pay_price'].'购买了'.$memberInfo['title'].'套餐。您获得的佣金是:'.$conf['first'].'%返佣,¥'.$secondLevel,'uniacid'=>$_GPC['uniacid']]);
-                          $a = $modelIncome->create([
-                                 'money' => $secondLevel,
-                                 'oid' => $order['id'],
-                                 'uid' => $teamUserInfo['pid'],
-                                 'buy_uid' => $order['uid'],
-                                 'buy_price'=>$order['pay_price'],
-                                 'mark' => '您的一级下线分销商内购,支付订单金额:¥'.$order['pay_price'].'购买了'.$memberInfo['title'].'套餐。您获得的佣金是:'.$conf['second'].'%返佣,¥'.$secondLevel,
-                                 'uniacid'=>$_GPC['uniacid'],
-                             ]);
-                      // }
-                  }
-                  if(!empty($teamUserInfo['gid'])){
-                      // 奖励给gid
-                      // 计算一级分销返佣
-                      $higherUserInfo = $modelUser::where('uid','=',$teamUserInfo['gid'])->find();
-                      if($higherUserInfo['status'] == 1){
-                          $banlance = $higherUserInfo['money'] + $thirdLevel;
-                          $modelUser::where('uid','=',$teamUserInfo['gid'])->update(['money'=>$banlance]);
-                          // $b = $modelIncome->save(['money'=>$thirdLevel,'uid'=>$teamUserInfo['gid'],'mark'=>'您的二级下线支付订单金额:¥'.$order['pay_price'].'购买了'.$memberInfo['title'].'套餐。您获得的佣金是:'.$conf['second'].'%返佣,¥'.$thirdLevel,'uniacid'=>$_GPC['uniacid']]);
-                          $b = $modelIncome->create([
-                                 'money' => $thirdLevel,
-                                 'uid' => $teamUserInfo['gid'],
-                                 'oid' => $order['id'],
-                                 'buy_uid' => $order['uid'],
-                                 'buy_price'=>$order['pay_price'],
-                                 'mark' => '您的二级下线分销商内购,支付订单金额:¥'.$order['pay_price'].'购买了'.$memberInfo['title'].'套餐。您获得的佣金是:'.$conf['third'].'%返佣,¥'.$thirdLevel,
-                                 'uniacid'=>$_GPC['uniacid'],
-                             ]);
-                      }
-                  }
-          } else {
-              if(!empty($teamUserInfo['pid'])){
-                  // 奖励给pid
-                  // 计算一级分销返佣
-                  $higherUserInfo = $modelUser::where('uid','=',$teamUserInfo['pid'])->find();
-                  if(!empty($higherUserInfo) && $higherUserInfo['status'] == 1){
-                      $banlance = $higherUserInfo['money'] + $firstLevel;
-                      $modelUser::where('uid','=',$teamUserInfo['pid'])->update(['money'=>$banlance]);
-                      // $a = $modelIncome->save(['money'=>$firstLevel,'uid'=>$teamUserInfo['pid'],'mark'=>'您的一级下线支付订单金额:¥'.$order['pay_price'].'购买了'.$memberInfo['title'].'套餐。您获得的佣金是:'.$conf['first'].'%返佣,¥'.$firstLevel,'uniacid'=>$_GPC['uniacid']]);
-                      $a = $modelIncome->create([
-                             'money' => $firstLevel,
-                             'oid' => $order['id'],
-                             'uid' => $teamUserInfo['pid'],
-                             'buy_uid' => $order['uid'],
-                             'buy_price'=>$order['pay_price'],
-                             'mark' => '您的一级下线支付订单金额:¥'.$order['pay_price'].'购买了'.$memberInfo['title'].'套餐。您获得的佣金是:'.$conf['first'].'%返佣,¥'.$firstLevel,
-                             'uniacid'=>$_GPC['uniacid'],
-                         ]);
-                  }
-              }
-              if(!empty($teamUserInfo['gid'])){
-                  // 奖励给gid
-                  // 计算一级分销返佣
-                  $higherUserInfo = $modelUser::where('uid','=',$teamUserInfo['gid'])->find();
-                  if(!empty($higherUserInfo) && $higherUserInfo['status'] == 1){
-                      $banlance = $higherUserInfo['money'] + $secondLevel;
-                      $modelUser::where('uid','=',$teamUserInfo['gid'])->update(['money'=>$banlance]);
-                      // $b = $modelIncome->save(['money'=>$secondLevel,'uid'=>$teamUserInfo['gid'],'mark'=>'您的二级下线支付订单金额:¥'.$order['pay_price'].'购买了'.$memberInfo['title'].'套餐。您获得的佣金是:'.$conf['second'].'%返佣,¥'.$secondLevel,'uniacid'=>$_GPC['uniacid']]);
-                      $b = $modelIncome->create([
-                             'money' => $secondLevel,
-                             'uid' => $teamUserInfo['gid'],
-                             'oid' => $order['id'],
-                             'buy_uid' => $order['uid'],
-                             'buy_price'=>$order['pay_price'],
-                             'mark' => '您的二级下线支付订单金额:¥'.$order['pay_price'].'购买了'.$memberInfo['title'].'套餐。您获得的佣金是:'.$conf['second'].'%返佣,¥'.$secondLevel,
-                             'uniacid'=>$_GPC['uniacid'],
-                         ]);
-                  }
-              }
-              if(!empty($teamUserInfo['gfid'])){
-                  // 奖励给gfid
-                  // 计算一级分销返佣
-                  $higherUserInfo = $modelUser::where('uid','=',$teamUserInfo['gfid'])->find();
-                  if(!empty($higherUserInfo) && $higherUserInfo['status'] == 1){
-                      $banlance = $higherUserInfo['money'] + $thirdLevel;
-                      $modelUser::where('uid','=',$teamUserInfo['gfid'])->update(['money'=>$banlance]);
-                      // $c = $modelIncome->save(['money'=>$thirdLevel,'uid'=>$teamUserInfo['gfid'],'mark'=>'您的三级下线支付订单金额:'.$order['pay_price'].'购买了'.$memberInfo['title'].'套餐。您获得的佣金是:'.$conf['third'].'%返佣,¥'.$secondLevel,'uniacid'=>$_GPC['uniacid']]);
-                      $c = $modelIncome->create([
-                             'money' => $thirdLevel,
-                             'uid' => $teamUserInfo['gfid'],
-                             'oid' => $order['id'],
-                             'buy_uid' => $order['uid'],
-                             'buy_price'=>$order['pay_price'],
-                             'mark' => '您的三级下线支付订单金额:¥'.$order['pay_price'].'购买了'.$memberInfo['title'].'套餐。您获得的佣金是:'.$conf['third'].'%返佣,¥'.$thirdLevel,
-                             'uniacid'=>$_GPC['uniacid'],
-                         ]);
-                  }
-              }
-          }
-
-      }
-  }
-
-}
+<?php
+
+namespace app\controller\api;
+use app\service\api\UserServiceFacade;
+// use app\service\api\MiniappServiceFacade;
+use app\service\api\PayServiceFacade;
+use app\service\api\HupijiaopayServiceFacade;
+use app\service\ConfServiceFacade;
+use app\service\BillServiceFacade;
+// use app\service\admin\CapitalFlowServiceFacade;
+use laytp\controller\Api;
+use think\facade\Request;
+// use think\facade\Queue;
+use app\service\MessageSystemServiceFacade;
+use think\facade\Queue;
+
+/**
+ * 获取系统配置
+ */
+class Pay extends Api{
+
+  protected function _initialize()
+  {
+      $this->model = new \app\model\Order();
+  }
+
+  // 无需登录的接口,*表示全部
+  public $noNeedLogin = ['notify','test','notifySettle','notifyHupijiao'];
+
+  public function hupijiaopay(){
+      global $_GPC;
+      $post = $this->request->post();
+      $isCommission = $this->request->post('is_commission',0);
+      $returnUrl = $this->request->post('return_url','');
+      $callbackUrl = $this->request->post('callback_url','');
+      $platform = $this->request->header('platform');
+      // 获得订单信息
+      if ($isCommission ==1) {
+          $notify = IS_R==1?request()->domain() . SURL . '/api.pay/notifySettleHupijiao':request()->domain() . SURL . '/index.php/api.pay/notifySettleHupijiao';
+          $pay_price = \app\model\commission\Settle::where(['order_number'=>$post['order_number']])->value('pay_price');
+      } else {
+          $notify = IS_R==1?request()->domain() . SURL . '/api.pay/notifyHupijiao':request()->domain() . SURL . '/index.php/api.pay/notifyHupijiao';
+          $pay_price = \app\model\Order::where(['order_number'=>$post['order_number']])->value('pay_price');
+      }
+      if(!$pay_price){
+        return $this->error('获取订单数据失败');
+      }
+
+      $data =[
+          'version' => 1.1,
+          'trade_order_id'=>$post['order_number'],
+          'total_fee'=>$pay_price,
+          'title'=>'充值',
+          'time'=>time(),
+          'notify_url'=>$notify,
+          'return_url' => $returnUrl,
+          'callback_url'=>$callbackUrl,
+          'type'=>'WAP',
+          'wap_name'=>'支付'
+      ];
+      $res = HupijiaopayServiceFacade::pay($data);
+      return $this->success('获取结果', $res);
+  }
+
+  public function prepay(){
+      global $_GPC;
+    $post = $this->request->post();
+    $platform = $this->request->post('platform');
+    $isCommission = $this->request->post('is_commission',0);
+
+    // 获得订单信息
+    if ($isCommission ==1) {
+        $notify = IS_R==1?request()->domain() . SURL . '/api.pay/notifySettle':request()->domain() . SURL . '/index.php/api.pay/notifySettle';
+        $pay_price = \app\model\commission\Settle::where(['order_number'=>$post['order_number']])->value('pay_price');
+    } else {
+        $notify = IS_R==1?request()->domain() . SURL . '/api.pay/notify':request()->domain() . SURL . '/index.php/api.pay/notify';
+        $pay_price = \app\model\Order::where(['order_number'=>$post['order_number']])->value('pay_price');
+    }
+    if(!$pay_price){
+      return $this->error('获取订单数据失败');
+    }
+    // print_r(request()->domain() . SURL . '/index.php/api.pay/notify');
+    $app  = PayServiceFacade::option($platform=='wxOfficialAccount'?'wechat':'miniapp');
+    $loginUserInfo = UserServiceFacade::getUserInfo();
+    // print_r($loginUserInfo);
+    $result = $app->order->unify([
+        'body' => '充值',
+        'out_trade_no' => $post['order_number'],
+        'total_fee' => $pay_price * 100,
+        'notify_url' => $notify, // 支付结果通知网址,如果不设置则会使用配置里的默认地址
+        'trade_type' => 'JSAPI', // 请对应换成你的支付方式对应的值类型
+        'openid' => $platform=='wxOfficialAccount'?$loginUserInfo['openid_wechat']:$loginUserInfo['openid_miniapp'],
+    ]);
+    $jssdk = $app->jssdk;
+    if($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS'){
+      $config = $jssdk->bridgeConfig($result['prepay_id'], false);
+      return $this->success('获取结果', $config);
+    }
+    return $this->error('获取失败,'.json_encode($result,320));
+  }
+
+  public function hupijiao()
+  {
+      global $_GPC;
+  }
+
+  public function notify(){
+    global $_GPC;
+    // $app = PayServiceFacade::option();
+    $notifiedData = file_get_contents('php://input');
+    $xmlObj = simplexml_load_string($notifiedData, 'SimpleXMLElement', LIBXML_NOCDATA);
+    $xmlObj = json_decode(json_encode($xmlObj), true);
+    // 库里查
+    $order = $this->model->where('order_number','=',$xmlObj['out_trade_no'])->find();
+    // 如果订单不存在 或者 订单已经支付过了
+    if(!$order || $order['paid'] == 1){
+      return true;  //已经处理 或该笔订单库里已经支付,微信你请勿再通知
+    }
+    if ($xmlObj['return_code'] === 'SUCCESS') { // return_code 表示通信状态,不代表支付状态
+        // 用户是否支付成功
+        if ($xmlObj['result_code'] === 'SUCCESS') {
+          // 用户支付成功
+          $_GPC['uniacid'] = $order['uniacid'];
+          $updateRes  = $this->model->where('order_number', '=', $xmlObj['out_trade_no'])->update(['paid'=>1, 'pay_time' => time()]);
+          $memberInfo = \app\model\Member::find($order['link_id']);
+          $this->setMember($order,$memberInfo);
+
+         // 分销
+         $this->setCommission($order,$memberInfo);
+
+          // $title = '下单支付成功通知';
+          // $content = '您的订单已支付,订单编号'.$xmlObj['out_trade_no'].',价格:¥'.$order['pay_price'];
+          // $jobQueueName ='wike_oddjob';
+          // $queueData =[
+          //     'uid' => $order['uid'],
+          //     'title'=>$title,
+          //     'content'=>$content,
+          //     'order_number'=>$xmlObj['out_trade_no'],
+          //     'pay_price'=>$order['pay_price'],
+          //     'status'=>'已支付',
+          //     'remark'=>'订单价格:'.$order['pay_price'],
+          //     'uniacid' => $order['uniacid']
+          // ];
+          // MessageSystemServiceFacade::Unified($order['uid'],$title,$content);
+          // $conf = ConfServiceFacade::groupGet('system.notification');
+          // if($conf['subscribe_status'] == 1){
+          //     Queue::later(3, 'app\jobs\SubscribeMessageJob@pay_suc', $queueData, $jobQueueName);
+          // }
+
+          // Queue::later(86400, 'app\jobs\SubscribeMessageJob@recommend', $queueData, $jobQueueName);
+          // Queue::later(432000, 'app\jobs\SubscribeMessageJob@new_video', $queueData, $jobQueueName);
+          if (!$updateRes) return false;
+        } elseif ($xmlObj['result_code'] === 'FAIL') {
+          // 用户支付失败
+          return false;
+        }
+    } else {
+        return false;
+    }
+    return true;
+    // file_put_contents(__DIR__ . '/ds.json', json_encode($xmlObj));
+  }
+
+  public function notifySettle(){
+    global $_GPC;
+    $modelSettle = new \app\model\commission\Settle();
+    $modelTeam =new \app\model\commission\Team();
+    $modelIncome =new \app\model\commission\Income();
+    $modelUser =new \app\model\commission\User();
+    // $app = PayServiceFacade::option();
+    $notifiedData = file_get_contents('php://input');
+    $xmlObj = simplexml_load_string($notifiedData, 'SimpleXMLElement', LIBXML_NOCDATA);
+    $xmlObj = json_decode(json_encode($xmlObj), true);
+    // 库里查
+    $order = $modelSettle->where('order_number','=',$xmlObj['out_trade_no'])->find();
+    // file_put_contents(__DIR__ . '/ds.json', json_encode($order));
+    // 如果订单不存在 或者 订单已经支付过了
+    if(!$order || $order['paid'] == 1){
+      return true;  //已经处理 或该笔订单库里已经支付,微信你请勿再通知
+    }
+    if ($xmlObj['return_code'] === 'SUCCESS') { // return_code 表示通信状态,不代表支付状态
+        // 用户是否支付成功
+        if ($xmlObj['result_code'] === 'SUCCESS') {
+          // 用户支付成功
+
+          $_GPC['uniacid'] = $order['uniacid'];
+          $updateRes  =$modelSettle->where('order_number', '=', $xmlObj['out_trade_no'])->update(['paid'=>1, 'pay_time' => time()]);
+          $updateRes2 = $modelUser->save(['paid' => 1,'uniacid'=>$order['uniacid'],'status'=>1,'paid'=>1,'uid'=>$order['uid'],'real_name'=>$order['real_name'],'telnum'=>$order['telnum'] ]);
+
+          // 分销
+
+          $teamUserInfo = $modelTeam::where('uid','=',$order['uid'])->find();
+          $conf = ConfServiceFacade::groupGet('system.commission');
+
+          if(!empty($conf['is_commission']) && $conf['is_commission']==1 ){
+              if($conf['first'] > 0){
+                 $firstLevel = $order['pay_price'] * ($conf['first'])/100;
+              }
+              if($conf['second'] > 0){
+                 $secondLevel = $order['pay_price'] * ($conf['second'])/100;
+              }
+              if($conf['third'] > 0){
+                 $thirdLevel = $order['pay_price'] * ($conf['third'])/100;
+              }
+
+                if(!empty($teamUserInfo['pid'])){
+                      // 奖励给pid
+                      // 计算一级分销返佣
+                      $higherUserInfo = $modelUser::where('uid','=',$teamUserInfo['pid'])->find();
+                      if(!empty($higherUserInfo) && $higherUserInfo['status'] == 1){
+                          $banlance = $higherUserInfo['money'] + $firstLevel;
+                          $modelUser::where('uid','=',$teamUserInfo['pid'])->update(['money'=>$banlance]);
+                          // $a = $modelIncome->save(['money'=>$firstLevel,'uid'=>$teamUserInfo['pid'],'mark'=>'您的一级下线支付订单金额:¥'.$order['pay_price'].'购买了'.$memberInfo['title'].'套餐。您获得的佣金是:'.$conf['first'].'%返佣,¥'.$firstLevel,'uniacid'=>$_GPC['uniacid']]);
+                          $a = $modelIncome->create([
+                                 'money' => $firstLevel,
+                                 'oid' => $order['id'],
+                                 'uid' => $teamUserInfo['pid'],
+                                 'buy_uid' => $order['uid'],
+                                 'buy_price'=>$order['pay_price'],
+                                 'mark' => '您的一级下线支付订单金额:¥'.$order['pay_price'].'入驻分销商。您获得的佣金是:'.$conf['first'].'%返佣,¥'.$firstLevel,
+                                 'uniacid'=>$_GPC['uniacid'],
+                             ]);
+                      }
+                  }
+                  if(!empty($teamUserInfo['gid'])){
+                      // 奖励给gid
+                      // 计算一级分销返佣
+                      $higherUserInfo = $modelUser::where('uid','=',$teamUserInfo['gid'])->find();
+                      if(!empty($higherUserInfo) && $higherUserInfo['status'] == 1){
+                          $banlance = $higherUserInfo['money'] + $secondLevel;
+                          $modelUser::where('uid','=',$teamUserInfo['gid'])->update(['money'=>$banlance]);
+                          // $b = $modelIncome->save(['money'=>$secondLevel,'uid'=>$teamUserInfo['gid'],'mark'=>'您的二级下线支付订单金额:¥'.$order['pay_price'].'购买了'.$memberInfo['title'].'套餐。您获得的佣金是:'.$conf['second'].'%返佣,¥'.$secondLevel,'uniacid'=>$_GPC['uniacid']]);
+                          $b = $modelIncome->create([
+                                 'money' => $secondLevel,
+                                 'uid' => $teamUserInfo['gid'],
+                                 'oid' => $order['id'],
+                                 'buy_uid' => $order['uid'],
+                                 'buy_price'=>$order['pay_price'],
+                                 'mark' => '您的二级下线支付订单金额:¥'.$order['pay_price'].'入驻分销商。您获得的佣金是:'.$conf['second'].'%返佣,¥'.$secondLevel,
+                                 'uniacid'=>$_GPC['uniacid'],
+                             ]);
+                      }
+                  }
+                  if(!empty($teamUserInfo['gfid'])){
+                      // 奖励给gfid
+                      // 计算一级分销返佣
+                      $higherUserInfo = $modelUser::where('uid','=',$teamUserInfo['gfid'])->find();
+                      if(!empty($higherUserInfo) && $higherUserInfo['status'] == 1){
+                          $banlance = $higherUserInfo['money'] + $thirdLevel;
+                          $modelUser::where('uid','=',$teamUserInfo['gfid'])->update(['money'=>$banlance]);
+                          // $c = $modelIncome->save(['money'=>$thirdLevel,'uid'=>$teamUserInfo['gfid'],'mark'=>'您的三级下线支付订单金额:'.$order['pay_price'].'购买了'.$memberInfo['title'].'套餐。您获得的佣金是:'.$conf['third'].'%返佣,¥'.$secondLevel,'uniacid'=>$_GPC['uniacid']]);
+                          $c = $modelIncome->create([
+                                 'money' => $thirdLevel,
+                                 'uid' => $teamUserInfo['gfid'],
+                                 'oid' => $order['id'],
+                                 'buy_uid' => $order['uid'],
+                                 'buy_price'=>$order['pay_price'],
+                                 'mark' => '您的三级下线支付订单金额:¥'.$order['pay_price'].'入驻分销商。您获得的佣金是:'.$conf['third'].'%返佣,¥'.$thirdLevel,
+                                 'uniacid'=>$_GPC['uniacid'],
+                             ]);
+                      }
+              }
+
+          }
+          if (!$updateRes) return false;
+        } elseif ($xmlObj['result_code'] === 'FAIL') {
+          // 用户支付失败
+          return false;
+        }
+    } else {
+        return false;
+    }
+    return true;
+    // file_put_contents(__DIR__ . '/ds.json', json_encode($xmlObj));
+  }
+
+  public function notifyHupijiao()
+  {
+      global $_GPC;
+      $post = $this->request->post();
+      // file_put_contents(__DIR__ . '/notifyHupijiao.json', json_encode($post));
+      // 库里查
+      $order = $this->model->where('order_number','=',$post['trade_order_id'])->find();
+      // file_put_contents(__DIR__ . '/ds.json', json_encode($order));
+      // 如果订单不存在 或者 订单已经支付过了
+      if(!$order || $order['paid'] == 1){
+        return true;  //已经处理 或该笔订单库里已经支付,微信你请勿再通知
+      }
+      if($post['status'] === 'OD'){
+          $_GPC['uniacid'] = $order['uniacid'];
+          $updateRes  = $this->model->where('order_number', '=', $post['trade_order_id'])->update(['paid'=>1, 'pay_time' => time(),'pay_channel'=>'hupijiao']);
+          $memberInfo = \app\model\Member::find($order['link_id']);
+          $this->setMember($order,$memberInfo);
+         // 分销
+         $this->setCommission($order,$memberInfo);
+      }
+      return 'success';
+  }
+
+  public function setMember($order,$memberInfo)
+  {
+      global $_GPC;
+
+      if(!empty($memberInfo) && !empty($memberInfo['type'])){
+         if($memberInfo['type']==2){
+             $modelVipinfo =new \app\model\Vipinfo();
+             $title = '充值时长';
+             $userInfo = \app\model\User::find($order['uid']);
+             if($memberInfo['day'] === 9999){
+                 $title = $title.'(永久)';
+                 $updateRes2 = \app\model\User::where('id', '=', $order['uid'])->update(['vip_time' => 9999]);
+             }else{
+                 $title = $title.'('.$memberInfo['day'].'天)';
+                 if($userInfo['vip_time'] < time()){
+                     $balance = strtotime("+".$memberInfo['day']."days");
+                 }else{
+                     // file_put_contents(__DIR__ . '/d.json', $memberInfo['day']*24*60*60);
+                     $balance = $userInfo['vip_time'] + $memberInfo['day']*24*60*60;
+                 }
+                 $updateRes2 = \app\model\User::where('id', '=', $order['uid'])->update(['vip_time' => $balance]);
+             }
+             BillServiceFacade::record(1,$memberInfo['coin'],'pay_member',$title,$order['uid'],$order['uniacid']);
+             // 写入余量
+             $vipinfo = $modelVipinfo->where('uid',$order['uid'])->find();
+             if(empty($vipinfo)){
+                 $save =[
+                     'uid'=>$order['uid'],
+                     'gpt35_times'=>$memberInfo['gpt35_times']?$memberInfo['gpt35_times']:0,
+                     'gpt4_times'=>$memberInfo['gpt4_times']?$memberInfo['gpt4_times']:0,
+                     'sd_times'=>$memberInfo['sd_times']?$memberInfo['sd_times']:0,
+                     'mj_times'=>$memberInfo['mj_times']?$memberInfo['mj_times']:0,
+                     'order_number'=>$order['order_number'],
+                     'member_id'=>$memberInfo['id'],
+                     'uniacid'=>$_GPC['uniacid']
+                 ];
+
+                 $res = $modelVipinfo->save($save);
+                 file_put_contents(__DIR__ . '/vipinfo.json', json_encode($res));
+             }else{
+                 $updata =[
+                     // 'gpt35_times'=>$memberInfo['gpt35_times']?$memberInfo['gpt35_times']:0,
+                     // 'gpt4_times'=>$memberInfo['gpt4_times']?$memberInfo['gpt4_times']:0,
+                     // 'sd_times'=>$memberInfo['sd_times']?$memberInfo['sd_times']:0,
+                     // 'mj_times'=>$memberInfo['mj_times']?$memberInfo['mj_times']:0,
+                     'order_number'=>$order['order_number'],
+                     'member_id'=>$memberInfo['id'],
+                     'uniacid'=>$_GPC['uniacid']
+                 ];
+                 if($memberInfo['gpt35_times'] == -1){
+                     $updata['gpt35_times'] = -1;
+                 }else{
+                     if($userInfo['vip_time'] <= time()){
+                         // 过期
+                             $updata['gpt35_times'] = $memberInfo['gpt35_times'];
+                     }else{
+                         if($vipinfo['gpt35_times']==-1){
+                            $updata['gpt35_times'] = -1;
+                         }else{
+                             $updata['gpt35_times'] = $vipinfo['gpt35_times'] + $memberInfo['gpt35_times'];
+                         }
+                     }
+
+                 }
+                 if($memberInfo['gpt4_times'] == -1){
+                     $updata['gpt4_times'] = -1;
+                 }else{
+                     if($userInfo['vip_time'] <= time()){
+                         $updata['gpt4_times'] = $memberInfo['gpt4_times'];
+                     }else{
+                         if($vipinfo['gpt4_times']==-1){
+                             $updata['gpt4_times'] = -1;
+                         }else{
+                             $updata['gpt4_times'] = $vipinfo['gpt4_times'] + $memberInfo['gpt4_times'];
+                         }
+
+                     }
+                 }
+                 if($memberInfo['sd_times'] == -1){
+                     $updata['sd_times'] = -1;
+                 }else{
+                     if($userInfo['vip_time'] <= time()){
+                         $updata['sd_times'] = $memberInfo['sd_times'];
+                     }else{
+                         if($vipinfo['sd_times']==-1){
+                             $updata['sd_times'] = -1;
+                         }else{
+                             $updata['sd_times'] = $vipinfo['sd_times'] + $memberInfo['sd_times'];
+                         }
+                     }
+                 }
+                 if($memberInfo['mj_times'] == -1){
+                     $updata['mj_times'] = -1;
+                 }else{
+                     if($userInfo['vip_time'] <= time()){
+                         $updata['mj_times'] = $memberInfo['mj_times'];
+                     }else{
+                         if($vipinfo['mj_times']==-1){
+                             $updata['mj_times'] = -1;
+                         }else{
+                             $updata['mj_times'] = $vipinfo['mj_times'] + $memberInfo['mj_times'];
+                         }
+                     }
+
+                 }
+                  $modelVipinfo->where('uid',$order['uid'])
+                  ->update($updata);
+             }
+         }else{
+              $updateRes2 = \app\model\User::where('id', '=', $order['uid'])->inc('coin',$memberInfo['coin'])->update();
+              BillServiceFacade::record(1,$memberInfo['coin'],'pay_member','充值次数',$order['uid'],$order['uniacid']);
+         }
+      }
+  }
+
+  public function setCommission($order,$memberInfo)
+  {
+      global $_GPC;
+
+      $modelTeam =new \app\model\commission\Team();
+      $modelIncome =new \app\model\commission\Income();
+      $modelUser =new \app\model\commission\User();
+      $teamUserInfo = $modelTeam::where('uid','=',$order['uid'])->find();
+      $conf = ConfServiceFacade::groupGet('system.commission');
+      // 获得购买者是否是分销商
+      $buyUserInfo= $modelUser::where('uid','=',$order['uid'])->find();
+      if(!empty($conf['is_commission']) && $conf['is_commission']==1 ){
+
+          if($conf['first'] > 0){
+             $firstLevel = $order['pay_price'] * ($conf['first'])/100;
+          }
+          if($conf['second'] > 0){
+             $secondLevel = $order['pay_price'] * ($conf['second'])/100;
+          }
+          if($conf['third'] > 0){
+             $thirdLevel = $order['pay_price'] * ($conf['third'])/100;
+          }
+
+          if(!empty($conf['is_self_buy']) &&  $conf['is_self_buy'] == 1 && !empty($buyUserInfo) && $buyUserInfo['status'] == 1){
+
+              // 开启自购
+               $higherUserInfo = $modelUser::where('uid','=',$order['uid'])->find();
+               $banlance = $higherUserInfo['money'] + $firstLevel;
+               $modelUser::where('uid','=',$order['uid'])->update(['money'=>$banlance]);
+               // $a = $modelIncome->save(['money'=>$firstLevel,'uid'=>$teamUserInfo['pid'],'mark'=>'您的一级下线支付订单金额:¥'.$order['pay_price'].'购买了'.$memberInfo['title'].'套餐。您获得的佣金是:'.$conf['first'].'%返佣,¥'.$firstLevel,'uniacid'=>$_GPC['uniacid']]);
+               $a = $modelIncome->create([
+                      'money' => $firstLevel,
+                      'oid' => $order['id'],
+                      'uid' => $order['uid'],
+                      'buy_uid' => $order['uid'],
+                      'buy_price'=>$order['pay_price'],
+                      'mark' => '自购返佣:您支付订单金额:¥'.$order['pay_price'].'购买了'.$memberInfo['title'].'套餐。您获得的佣金是:'.$conf['first'].'%返佣,¥'.$firstLevel,
+                      'uniacid'=>$_GPC['uniacid'],
+                  ]);
+                  if(!empty($teamUserInfo['pid'])){
+                      // 奖励给pid
+                      // 计算一级分销返佣
+                      $higherUserInfo = $modelUser::where('uid','=',$teamUserInfo['pid'])->find();
+                      // if($higherUserInfo['status'] == 1){
+                          $banlance = $higherUserInfo['money'] + $secondLevel;
+                          $modelUser::where('uid','=',$teamUserInfo['pid'])->update(['money'=>$banlance]);
+                          // $a = $modelIncome->save(['money'=>$secondLevel,'uid'=>$teamUserInfo['pid'],'mark'=>'您的一级下线支付订单金额:¥'.$order['pay_price'].'购买了'.$memberInfo['title'].'套餐。您获得的佣金是:'.$conf['first'].'%返佣,¥'.$secondLevel,'uniacid'=>$_GPC['uniacid']]);
+                          $a = $modelIncome->create([
+                                 'money' => $secondLevel,
+                                 'oid' => $order['id'],
+                                 'uid' => $teamUserInfo['pid'],
+                                 'buy_uid' => $order['uid'],
+                                 'buy_price'=>$order['pay_price'],
+                                 'mark' => '您的一级下线分销商内购,支付订单金额:¥'.$order['pay_price'].'购买了'.$memberInfo['title'].'套餐。您获得的佣金是:'.$conf['second'].'%返佣,¥'.$secondLevel,
+                                 'uniacid'=>$_GPC['uniacid'],
+                             ]);
+                      // }
+                  }
+                  if(!empty($teamUserInfo['gid'])){
+                      // 奖励给gid
+                      // 计算一级分销返佣
+                      $higherUserInfo = $modelUser::where('uid','=',$teamUserInfo['gid'])->find();
+                      if($higherUserInfo['status'] == 1){
+                          $banlance = $higherUserInfo['money'] + $thirdLevel;
+                          $modelUser::where('uid','=',$teamUserInfo['gid'])->update(['money'=>$banlance]);
+                          // $b = $modelIncome->save(['money'=>$thirdLevel,'uid'=>$teamUserInfo['gid'],'mark'=>'您的二级下线支付订单金额:¥'.$order['pay_price'].'购买了'.$memberInfo['title'].'套餐。您获得的佣金是:'.$conf['second'].'%返佣,¥'.$thirdLevel,'uniacid'=>$_GPC['uniacid']]);
+                          $b = $modelIncome->create([
+                                 'money' => $thirdLevel,
+                                 'uid' => $teamUserInfo['gid'],
+                                 'oid' => $order['id'],
+                                 'buy_uid' => $order['uid'],
+                                 'buy_price'=>$order['pay_price'],
+                                 'mark' => '您的二级下线分销商内购,支付订单金额:¥'.$order['pay_price'].'购买了'.$memberInfo['title'].'套餐。您获得的佣金是:'.$conf['third'].'%返佣,¥'.$thirdLevel,
+                                 'uniacid'=>$_GPC['uniacid'],
+                             ]);
+                      }
+                  }
+          } else {
+              if(!empty($teamUserInfo['pid'])){
+                  // 奖励给pid
+                  // 计算一级分销返佣
+                  $higherUserInfo = $modelUser::where('uid','=',$teamUserInfo['pid'])->find();
+                  if(!empty($higherUserInfo) && $higherUserInfo['status'] == 1){
+                      $banlance = $higherUserInfo['money'] + $firstLevel;
+                      $modelUser::where('uid','=',$teamUserInfo['pid'])->update(['money'=>$banlance]);
+                      // $a = $modelIncome->save(['money'=>$firstLevel,'uid'=>$teamUserInfo['pid'],'mark'=>'您的一级下线支付订单金额:¥'.$order['pay_price'].'购买了'.$memberInfo['title'].'套餐。您获得的佣金是:'.$conf['first'].'%返佣,¥'.$firstLevel,'uniacid'=>$_GPC['uniacid']]);
+                      $a = $modelIncome->create([
+                             'money' => $firstLevel,
+                             'oid' => $order['id'],
+                             'uid' => $teamUserInfo['pid'],
+                             'buy_uid' => $order['uid'],
+                             'buy_price'=>$order['pay_price'],
+                             'mark' => '您的一级下线支付订单金额:¥'.$order['pay_price'].'购买了'.$memberInfo['title'].'套餐。您获得的佣金是:'.$conf['first'].'%返佣,¥'.$firstLevel,
+                             'uniacid'=>$_GPC['uniacid'],
+                         ]);
+                  }
+              }
+              if(!empty($teamUserInfo['gid'])){
+                  // 奖励给gid
+                  // 计算一级分销返佣
+                  $higherUserInfo = $modelUser::where('uid','=',$teamUserInfo['gid'])->find();
+                  if(!empty($higherUserInfo) && $higherUserInfo['status'] == 1){
+                      $banlance = $higherUserInfo['money'] + $secondLevel;
+                      $modelUser::where('uid','=',$teamUserInfo['gid'])->update(['money'=>$banlance]);
+                      // $b = $modelIncome->save(['money'=>$secondLevel,'uid'=>$teamUserInfo['gid'],'mark'=>'您的二级下线支付订单金额:¥'.$order['pay_price'].'购买了'.$memberInfo['title'].'套餐。您获得的佣金是:'.$conf['second'].'%返佣,¥'.$secondLevel,'uniacid'=>$_GPC['uniacid']]);
+                      $b = $modelIncome->create([
+                             'money' => $secondLevel,
+                             'uid' => $teamUserInfo['gid'],
+                             'oid' => $order['id'],
+                             'buy_uid' => $order['uid'],
+                             'buy_price'=>$order['pay_price'],
+                             'mark' => '您的二级下线支付订单金额:¥'.$order['pay_price'].'购买了'.$memberInfo['title'].'套餐。您获得的佣金是:'.$conf['second'].'%返佣,¥'.$secondLevel,
+                             'uniacid'=>$_GPC['uniacid'],
+                         ]);
+                  }
+              }
+              if(!empty($teamUserInfo['gfid'])){
+                  // 奖励给gfid
+                  // 计算一级分销返佣
+                  $higherUserInfo = $modelUser::where('uid','=',$teamUserInfo['gfid'])->find();
+                  if(!empty($higherUserInfo) && $higherUserInfo['status'] == 1){
+                      $banlance = $higherUserInfo['money'] + $thirdLevel;
+                      $modelUser::where('uid','=',$teamUserInfo['gfid'])->update(['money'=>$banlance]);
+                      // $c = $modelIncome->save(['money'=>$thirdLevel,'uid'=>$teamUserInfo['gfid'],'mark'=>'您的三级下线支付订单金额:'.$order['pay_price'].'购买了'.$memberInfo['title'].'套餐。您获得的佣金是:'.$conf['third'].'%返佣,¥'.$secondLevel,'uniacid'=>$_GPC['uniacid']]);
+                      $c = $modelIncome->create([
+                             'money' => $thirdLevel,
+                             'uid' => $teamUserInfo['gfid'],
+                             'oid' => $order['id'],
+                             'buy_uid' => $order['uid'],
+                             'buy_price'=>$order['pay_price'],
+                             'mark' => '您的三级下线支付订单金额:¥'.$order['pay_price'].'购买了'.$memberInfo['title'].'套餐。您获得的佣金是:'.$conf['third'].'%返佣,¥'.$thirdLevel,
+                             'uniacid'=>$_GPC['uniacid'],
+                         ]);
+                  }
+              }
+          }
+
+      }
+  }
+
+}

+ 3 - 0
app/controller/api/User.php

xqd
@@ -147,6 +147,9 @@ class User extends Api
         if(!($post['nickname'] || $post['avatar'])){
             return $this->error('修改失败,请上传要修改的头像或昵称等信息');
         }
+        if (!empty($post['password'])){
+            $post['password'] = Str::createPassword($post['password']);
+        }
         $loginUserInfo = UserServiceFacade::getUserInfo();
         $updateRes = $this->model->where('id', '=', $loginUserInfo['id'])->update($post);
         if (!$updateRes) throw new \Exception('保存基本信息失败');

+ 1 - 1
app/controller/api/ds.json

xqd
@@ -1 +1 @@
-{"message":"unexpected end of JSON input","type":"one_api_error","param":"","code":"unmarshal_response_body_failed"}
+{"message":"This model's maximum context length is 4097 tokens. However, your messages resulted in 4316 tokens. Please reduce the length of the messages.","type":"invalid_request_error","param":"messages","code":"context_length_exceeded"}

+ 1 - 1
app/controller/api/ds2.json

xqd
@@ -1 +1 @@
-{"type":"gpt4","url":"https:\/\/api.gptmf.top\/v1\/chat\/completions","sk":"sk-Lumo32Jh23arN9pcA9AcD9605eA24cB0Bb531cBeCcB1B35f","model":"gpt-4-0613"}
+{"type":"gpt35","url":"https:\/\/proxy3.wike.cc\/v1\/chat\/completions","sk":"","model":"gpt-3.5-turbo-0613","mode":"no_key"}

+ 10 - 0
app/model/AudioList.php

xqd
@@ -0,0 +1,10 @@
+<?php
+
+namespace app\model;
+
+use think\Model;
+
+class AudioList extends Model
+{
+
+}

+ 18 - 0
app/model/BackConfig.php

xqd
@@ -0,0 +1,18 @@
+<?php
+
+namespace app\model;
+
+use think\Model;
+
+class BackConfig extends Model
+{
+ protected $table = 'back_config';
+
+}
+
+
+
+
+
+
+

+ 10 - 0
app/model/BackList.php

xqd
@@ -0,0 +1,10 @@
+<?php
+
+namespace app\model;
+
+use think\Model;
+
+class BackList extends Model
+{
+
+}

+ 10 - 0
app/model/DigitUser.php

xqd
@@ -0,0 +1,10 @@
+<?php
+
+namespace app\model;
+
+use think\Model;
+
+class DigitUser extends Model
+{
+//    protected $table = 'digit_user';
+}

+ 10 - 0
app/model/RoleList.php

xqd
@@ -0,0 +1,10 @@
+<?php
+
+namespace app\model;
+
+use think\Model;
+
+class RoleList extends Model
+{
+
+}

+ 18 - 0
app/model/TaskList.php

xqd
@@ -0,0 +1,18 @@
+<?php
+
+namespace app\model;
+
+use think\Model;
+
+class TaskList extends Model
+{
+    public function audios(){
+         return $this->hasOne(AudioList::class,'id','audio');
+    }
+    public function backs(){
+        return $this->hasOne(BackList::class,'id','back');
+    }
+    public function roles(){
+        return $this->hasOne(RoleList::class,'id','role');
+    }
+}

+ 11 - 3
app/model/commission/Team.php

xqd xqd
@@ -4,6 +4,8 @@
  */
 namespace app\model\commission;
 
+use app\model\Gallery;
+use app\model\Question;
 use laytp\BaseModel;
 use laytp\library\UploadDomain;
 use think\model\concern\SoftDelete;
@@ -31,9 +33,15 @@ class Team extends BaseModel
     public function pidUserinfo(){
         return $this->belongsTo('app\model\User','pid','id')->bind(['nickname','avatar','id_number'])->field(['id','nickname','avatar','id_number']);
     }
-
-
-
+    public function questionCount(){
+        return $this->hasMany(Question::class,'uid','uid');
+    }
+    public function galleryCount(){
+        return $this->hasMany(Gallery::class,'uid','uid');
+    }
+    public function payMoney(){
+        return $this->hasMany(\app\model\Order::class,'uid','uid')->where('paid',1)->sum('pay_price');
+    }
     //新增属性的方法
     public function getCreateTimeIntAttr($value, $data)
 	{

File diff suppressed because it is too large
+ 0 - 1
app/service/Bill.php


File diff suppressed because it is too large
+ 0 - 0
app/service/Chatgpt.php


File diff suppressed because it is too large
+ 0 - 1
app/service/Member.php


File diff suppressed because it is too large
+ 1 - 249
app/service/api/Ins.php


+ 4 - 2
app/service/api/User.php

xqd xqd xqd xqd
@@ -2,6 +2,7 @@
 
 namespace app\service\api;
 
+use app\model\Order;
 use laytp\library\Str;
 use laytp\library\Token;
 use laytp\traits\Error;
@@ -18,7 +19,7 @@ class User
     protected $_token = null;//用户登录凭证,token
     protected $_isLogin = null;//当前用户是否登录
     protected $userModel = null;//用户数据模型
-    protected $allowFields = ['id', 'nickname', 'avatar', 'status', 'create_time','create_time_int','phone','openid_miniapp','openid_wechat','coin','id_number','vip_time'];
+    protected $allowFields = ['id', 'nickname', 'avatar', 'status', 'create_time','create_time_int','phone','name','openid_miniapp','openid_wechat','coin','id_number','vip_time'];
     protected $tokenKeepTime = 0;//Token默认有效时长,单位秒,365天
 
     /**
@@ -37,7 +38,6 @@ class User
             $this->setError('token不能为空,请重新登录');
             return false;
         }
-
         $data = Token::get($token);
         if (!$data) {
             $this->setError('token无效,请重新登录');
@@ -101,6 +101,8 @@ class User
         $allowFields = $this->getAllowFields();
         $userInfo    = array_intersect_key($data, array_flip($allowFields));
         $userInfo    = array_merge($userInfo, ['token' => $this->_token]);
+        $order = Order::where('uid',$userInfo['id'])->where('paid',1)->find();
+        $userInfo    = array_merge($userInfo, ['is_new' => empty($userInfo['phone']) && $order]);
         return $userInfo;
     }
 

BIN
app/service/service_88szm2.tar.gz


+ 18 - 0
app/validate/DigitValidate.php

xqd
@@ -0,0 +1,18 @@
+<?php
+
+namespace app\validate;
+
+use think\Validate;
+
+class DigitValidate extends Validate
+{
+    protected $rule = [
+        'name'  => 'require|max:25',
+        'content' => 'require|max:2000',
+        'role' => 'require|integer',
+        'back' => 'require|integer',
+        'audio' => 'require|integer',
+        'stage' => 'require|float',
+    ];
+
+}

+ 72 - 0
config.php

xqd
@@ -0,0 +1,72 @@
+<?php
+defined('IN_IA') or exit('Access Denied');
+
+$config = array();
+
+$config['db']['master']['host'] = '47.94.228.245';
+$config['db']['master']['username'] = 'root';
+$config['db']['master']['password'] = 'MthJ5rcwyyEXC6nB';
+$config['db']['master']['port'] = '3306';
+$config['db']['master']['database'] = 'digit';
+$config['db']['master']['charset'] = 'utf8mb4';
+$config['db']['master']['pconnect'] = 0;
+$config['db']['master']['tablepre'] = 'ims_';
+
+$config['db']['slave_status'] = false;
+$config['db']['slave']['1']['host'] = '';
+$config['db']['slave']['1']['username'] = '';
+$config['db']['slave']['1']['password'] = '';
+$config['db']['slave']['1']['port'] = '3307';
+$config['db']['slave']['1']['database'] = '';
+$config['db']['slave']['1']['charset'] = 'utf8';
+$config['db']['slave']['1']['pconnect'] = 0;
+$config['db']['slave']['1']['tablepre'] = 'ims_';
+$config['db']['slave']['1']['weight'] = 0;
+
+$config['db']['common']['slave_except_table'] = array('core_sessions');
+
+// --------------------------  CONFIG COOKIE  --------------------------- //
+$config['cookie']['pre'] = '0U3y_';
+$config['cookie']['domain'] = '';
+$config['cookie']['path'] = '/';
+
+// --------------------------  CONFIG SETTING  --------------------------- //
+$config['setting']['charset'] = 'utf-8';
+$config['setting']['cache'] = 'redis';
+$config['setting']['timezone'] = 'Asia/Shanghai';
+$config['setting']['memory_limit'] = '256M';
+$config['setting']['filemode'] = 0644;
+$config['setting']['authkey'] = 'JLHbiMwS';
+$config['setting']['founder'] = '1';
+$config['setting']['development'] = 0;
+$config['setting']['referrer'] = 0;
+
+// --------------------------  CONFIG UPLOAD  --------------------------- //
+$config['upload']['image']['extentions'] = array('gif', 'jpg', 'jpeg', 'png');
+$config['upload']['image']['limit'] = 5000;
+$config['upload']['attachdir'] = 'attachment';
+$config['upload']['audio']['extentions'] = array('mp3','mp4','wav','mov');
+$config['upload']['audio']['limit'] = 5000;
+
+// --------------------------  CONFIG MEMCACHE  --------------------------- //
+$config['setting']['memcache']['server'] = '';
+$config['setting']['memcache']['port'] = 11211;
+$config['setting']['memcache']['pconnect'] = 1;
+$config['setting']['memcache']['timeout'] = 30;
+$config['setting']['memcache']['session'] = 1;
+
+$config['setting']['redis']['server'] = '127.0.0.1'; 
+$config['setting']['redis']['port'] = 6379; 
+$config['setting']['redis']['pconnect'] = 0; 
+$config['setting']['redis']['requirepass'] = ''; 
+$config['setting']['redis']['timeout'] = 1;
+
+// --------------------------  CONFIG PROXY  --------------------------- //
+$config['setting']['proxy']['host'] = '';
+$config['setting']['proxy']['auth'] = '';
+
+// --------------------------  CONFIG WORKMAN  --------------------------- //
+$config['setting']['workerman']['server'] = '0.0.0.0';
+$config['setting']['workerman']['port'] = 2345;
+
+

+ 5 - 5
config/config.php

xqd xqd
@@ -15,7 +15,7 @@ if (!empty(SYS_TYPE)) {
         ];
     }else{
         // W7
-        require dirname(dirname(dirname(__DIR__))) . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'config.php';
+        require dirname(__DIR__) . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'config.php';
         if(!empty($config['db']['master'])){
             $configDb = $config['db']['master'];
         }else{
@@ -29,13 +29,13 @@ if (!empty(SYS_TYPE)) {
 
 } else {
     $configDb = array(
-        'host' => '127.0.0.1',
+        'host' => '47.94.228.245',
         // 数据库名
-        'database' => '',
+        'database' => 'digits',
         // 用户名
-        'username' => '',
+        'username' => 'root',
         // 密码
-        'password' => '',
+        'password' => 'MthJ5rcwyyEXC6nB',
         // 端口
         'port' => 3306,
         // 数据库编码默认采用utf8

BIN
extend/.DS_Store


+ 2 - 2
extend/auth/AuthInfo.php

xqd
@@ -2,8 +2,8 @@
 // 授权信息类
 class AuthInfo{
     const AUTHCODE = '60d31eb37595dd44584be5ef363283e3';
-    const VERSION = 483;
-    const EDITION = '4.8.3';
+    const VERSION = 465;
+    const EDITION = '4.6.5';
     const PUBLIC_KEY = '-----BEGIN PUBLIC KEY-----
 MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAumYe9wWWL2cZgVB7m77F
 ERAAa91SsGHNG/f6GYj005p7INRiTAdAaHnf9uxT9SUhhuyis2f7WhjyqHx8shqF

File diff suppressed because it is too large
+ 0 - 0
extend/auth/Authorization.php


+ 0 - 0
extend/auth/Authorization.zip


+ 1 - 1
extend/baiduai/lib/75f788afb0bb2f084e4c5137eaaf8628

xqd
@@ -1 +1 @@
-{"refresh_token":"25.7f27304eb02e418e67702b6a8db9a9de.315360000.2004422772.282335-32229701","expires_in":2592000,"session_key":"9mzdDA13D9M326z8aSS\/4bFoTZbRBSunhJTlR6zFsjm1n5ciF2eDDQd8bLHGlG944iKMQOdRgeafzv55BZ7p8VKtQpVRkA==","access_token":"24.78d2e6cee76e20117f2cd7872ee048e2.2592000.1691654772.282335-32229701","scope":"audio_voice_assistant_get brain_enhanced_asr audio_tts_post brain_speech_realtime public brain_all_scope brain_asr_async wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test\u6743\u9650 vis-classify_flower lpq_\u5f00\u653e cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base smartapp_mapp_dev_manage iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_\u5f00\u653eScope vis-ocr_\u865a\u62df\u4eba\u7269\u52a9\u7406 idl-video_\u865a\u62df\u4eba\u7269\u52a9\u7406 smartapp_component smartapp_search_plugin avatar_video_test b2b_tp_openapi b2b_tp_openapi_online smartapp_gov_aladin_to_xcx","session_secret":"b5eb6688b4c718ae7b4b29c7151357fd","time":1689062773,"is_cloud_user":false}
+{"refresh_token":"25.88bb57c496b1d3007666b7e814241573.315360000.2000566518.282335-32229701","expires_in":2592000,"session_key":"9mzdA8tztvLuQj2AasmqXKLhSR\/TO2IlNGfb5GjOItSz\/xJjucF8rSl1rFtAs7HaBFuCCfENHAIpvEtv0fedUYuQI14MNQ==","access_token":"24.8a5374c0387dcf5a9ce1b7150c4cd86f.2592000.1687798518.282335-32229701","scope":"audio_voice_assistant_get brain_enhanced_asr audio_tts_post brain_speech_realtime public brain_all_scope brain_asr_async wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test\u6743\u9650 vis-classify_flower lpq_\u5f00\u653e cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base smartapp_mapp_dev_manage iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_\u5f00\u653eScope vis-ocr_\u865a\u62df\u4eba\u7269\u52a9\u7406 idl-video_\u865a\u62df\u4eba\u7269\u52a9\u7406 smartapp_component smartapp_search_plugin avatar_video_test b2b_tp_openapi b2b_tp_openapi_online smartapp_gov_aladin_to_xcx","session_secret":"f02cd6a904e76a675dd78252a3aea960","time":1685206520,"is_cloud_user":false}

+ 1 - 1
extend/baiduai/lib/ca8bbcf6b966253d94b000f201de4b28

xqd
@@ -1 +1 @@
-{"refresh_token":"25.5246bad27b605786d68512967aa30544.315360000.2006233275.282335-31701881","expires_in":2592000,"session_key":"9mzdCuZBAzaDaD4oTxfuGLhf0aMDoIh2o4605iEk73HNciv82x3XmnsLESmWJV6P\/vk+tRasVCjQvfV3rg8SNfLTp1qT7g==","access_token":"24.1bcf6d5894d107ae25508f40298a6310.2592000.1693465275.282335-31701881","scope":"public brain_all_scope solution_face wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test\u6743\u9650 vis-classify_flower lpq_\u5f00\u653e cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base smartapp_mapp_dev_manage iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_\u5f00\u653eScope vis-ocr_\u865a\u62df\u4eba\u7269\u52a9\u7406 idl-video_\u865a\u62df\u4eba\u7269\u52a9\u7406 smartapp_component smartapp_search_plugin avatar_video_test b2b_tp_openapi b2b_tp_openapi_online smartapp_gov_aladin_to_xcx","session_secret":"3758682e73d02a662c8861a1f593340d","time":1690873275,"is_cloud_user":false}
+{"refresh_token":"25.71d81df5325d61359e359d7748df4887.315360000.2003332102.282335-31701881","expires_in":2592000,"session_key":"9mzdCPR9FpnHoo+sM5Ak9sWLpHDLqGy\/RxeX9TKpp\/pUXZsPdwPPy0TW5pBHOshm+PNW35HRLzLXUSMNjmHKw0QvrlLDdw==","access_token":"24.303e942305cb81c6ad6fec59d3b48c6e.2592000.1690564102.282335-31701881","scope":"public brain_all_scope solution_face wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test\u6743\u9650 vis-classify_flower lpq_\u5f00\u653e cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base smartapp_mapp_dev_manage iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_\u5f00\u653eScope vis-ocr_\u865a\u62df\u4eba\u7269\u52a9\u7406 idl-video_\u865a\u62df\u4eba\u7269\u52a9\u7406 smartapp_component smartapp_search_plugin avatar_video_test b2b_tp_openapi b2b_tp_openapi_online smartapp_gov_aladin_to_xcx","session_secret":"f5815b94538f333e3138083bb2488ba7","time":1687972102,"is_cloud_user":false}

+ 1 - 1
extend/baiduai/lib/fc49e89977addb437669673eea215c11

xqd
@@ -1 +1 @@
-{"refresh_token":"25.34491f3dfa50145890cabe8304709189.315360000.2006085998.282335-6679432","expires_in":2592000,"session_key":"9mzdWEHj+3aaQNo7lCU\/opnJdATsIlGAUOF8AsKHLZxd\/EV1xk5fBg0B5o4kzSd47vAt2Xe+1QI+e5K2d4mm2Gkhw54W","access_token":"24.c16ba74f402c4e89330d6c938fc6aec8.2592000.1693317998.282335-6679432","scope":"audio_voice_assistant_get brain_enhanced_asr brain_speech_realtime audio_tts_post public wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test\u6743\u9650 vis-classify_flower lpq_\u5f00\u653e cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base smartapp_mapp_dev_manage iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_\u5f00\u653eScope vis-ocr_\u865a\u62df\u4eba\u7269\u52a9\u7406 idl-video_\u865a\u62df\u4eba\u7269\u52a9\u7406 smartapp_component smartapp_search_plugin avatar_video_test b2b_tp_openapi b2b_tp_openapi_online smartapp_gov_aladin_to_xcx","session_secret":"b57aafa6ab1d8c3b48fadf5e40e4db95","time":1690725998,"is_cloud_user":false}
+{"refresh_token":"25.6e010a065996f8eafff0b653162d6450.315360000.2003454331.282335-6679432","expires_in":2592000,"session_key":"9mzdDovAxs7uWlCoCPfszdnPXlzqWmeTGcyAFXf989WmOEHb26TU2qHAqselma6M4T751cJAUE5FQa+IB2mDd16kcrLL","access_token":"24.597ca2751de6f54fed72d1b40b40da51.2592000.1690686331.282335-6679432","scope":"audio_tts_post public wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test\u6743\u9650 vis-classify_flower lpq_\u5f00\u653e cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base smartapp_mapp_dev_manage iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_\u5f00\u653eScope vis-ocr_\u865a\u62df\u4eba\u7269\u52a9\u7406 idl-video_\u865a\u62df\u4eba\u7269\u52a9\u7406 smartapp_component smartapp_search_plugin avatar_video_test b2b_tp_openapi b2b_tp_openapi_online smartapp_gov_aladin_to_xcx","session_secret":"5e6b45b6ed7cf7e57ab6d6a905e0b250","time":1688094332,"is_cloud_user":false}

+ 3 - 3
extend/laytp/library/UploadDomain.php

xqd
@@ -33,9 +33,9 @@ class UploadDomain
         if (!$this->checkExt($fileName, $fileExt, $allowExt)) {
             return false;
         }
-        if (!$this->checkMime($fileMime)) {
-            return false;
-        }
+//        if (!$this->checkMime($fileMime)) {
+//            return false;
+//        }
         return true;
     }
 

+ 211 - 0
framework/bootstrap.inc.php

xqd
@@ -0,0 +1,211 @@
+<?php
+/**
+ * [WeEngine System] Copyright (c) 2014 WE7.CC
+ * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
+ */
+define('IN_IA', true);
+define('IA_ROOT', str_replace('\\', '/', dirname(dirname(__FILE__))));
+define('STARTTIME', microtime());
+define('MAGIC_QUOTES_GPC', (version_compare(PHP_VERSION, '7.4.0', '<') ? function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc() : 0) || @ini_get('magic_quotes_sybase'));
+define('TIMESTAMP', time());
+//var_dump(IA_ROOT);
+$configfile = IA_ROOT . '/config.php';
+if (!file_exists($configfile)) {
+	header('Content-Type: text/html; charset=utf-8');
+	exit('配置文件不存在或是不可读,请检查“data/config.php”文件或是<a href="./install.php"> 重新安装 </a>!');
+}
+require $configfile;
+$_W = $_GPC = array();
+$_W['config'] = $config;
+
+$allow_origin = array('https://user.w7.cc', 'https://m.w7.cc', 'https://console.w7.cc', 'http://console.w7.cc', 'http://user.w7.cc', 'http://m.w7.cc');
+if (!empty($_W['config']['setting']['allow_origin']) && is_array($_W['config']['setting']['allow_origin'])) {
+	$allow_origin = array_merge($allow_origin, $_W['config']['setting']['allow_origin']);
+}
+if (isset($_SERVER['HTTP_ORIGIN']) && in_array($_SERVER['HTTP_ORIGIN'], $allow_origin)) {
+	header('Access-Control-Allow-Headers:Origin,X-Requested-With,Content-Type,Accept,Authorization,cancelload,X-W7-Oauthtoken,W7-Oauthtoken');
+	header('Access-Control-Allow-Credentials:true');
+	header('Access-Control-Allow-Method:POST,GET,OPTIONS');
+	header('Access-Control-Allow-Origin:' . $_SERVER['HTTP_ORIGIN']);
+}
+if ('OPTIONS' == (isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : '')) {
+	$vars = array();
+	$vars['message'] = array('errno' => 0, 'message' => null);
+	$vars['redirect'] = '';
+	$vars['type'] = 'ajax';
+	exit(json_encode($vars));
+}
+require IA_ROOT . '/framework/const.inc.php';
+require IA_ROOT . '/framework/class/loader.class.php';
+load()->func('global');
+load()->func('compat');
+load()->func('compat.biz');
+load()->func('pdo');
+load()->classs('account');
+load()->model('cache');
+load()->model('account');
+load()->model('setting');
+load()->model('module');
+load()->library('agent');
+load()->classs('db');
+load()->func('communication');
+
+define('CLIENT_IP', getip());
+
+$_W['config']['db']['tablepre'] = !empty($_W['config']['db']['master']['tablepre']) ? $_W['config']['db']['master']['tablepre'] : $_W['config']['db']['tablepre'];
+$_W['timestamp'] = TIMESTAMP;
+$_W['charset'] = $_W['config']['setting']['charset'];
+$_W['clientip'] = CLIENT_IP;
+
+if (!empty($_W['config']['setting']['https']) && $_W['config']['setting']['https'] == '1') {
+	$_W['ishttps'] = $_W['config']['setting']['https'];
+} else {
+	$_W['ishttps'] = !empty($_SERVER['SERVER_PORT']) && 443 == $_SERVER['SERVER_PORT'] ||
+	!empty($_SERVER['HTTP_FROM_HTTPS']) && 'on' == strtolower($_SERVER['HTTP_FROM_HTTPS']) ||
+	(!empty($_SERVER['HTTPS']) && 'off' != strtolower($_SERVER['HTTPS'])) ||
+	!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && 'https' == strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']) ||
+	!empty($_SERVER['HTTP_X_CLIENT_SCHEME']) && 'https' == strtolower($_SERVER['HTTP_X_CLIENT_SCHEME']) || 
+	!empty($_SERVER['HTTP_X_CLIENT_PROTO']) && 'https' == strtolower($_SERVER['HTTP_X_CLIENT_PROTO']) 
+		? STATUS_ON : STATUS_OFF;
+}
+$_W['sitescheme'] = $_W['ishttps'] ? 'https://' : 'http://';
+$_W['script_name'] = htmlspecialchars(scriptname());
+$sitepath = substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/'));
+$_W['siteroot'] = htmlspecialchars($_W['sitescheme'] . (!empty($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '') . $sitepath);
+
+if ('/' != substr($_W['siteroot'], -1)) {
+	$_W['siteroot'] .= '/';
+}
+$urls = parse_url($_W['siteroot']);
+$urls['path'] = empty($urls['path']) ? '' : $urls['path'];
+$urls['path'] = str_replace(array('/web', '/app', '/payment/wechat', '/payment/alipay', '/api'), '', $urls['path']);
+$urls['scheme'] = !empty($urls['scheme']) ? $urls['scheme'] : 'http';
+$urls['host'] = !empty($urls['host']) ? $urls['host'] : '';
+$_W['siteroot'] = $urls['scheme'] . '://' . $urls['host'] . ((!empty($urls['port']) && '80' != $urls['port']) ? ':' . $urls['port'] : '') . $urls['path'];
+
+$_W['isajax'] = !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && 'xmlhttprequest' == strtolower($_SERVER['HTTP_X_REQUESTED_WITH']);
+
+$pdo_if_start = (pdo()->getPDO() instanceof PDO);
+if (!$pdo_if_start && file_exists(IA_ROOT . '/install.php')) {
+	header('Content-Type: text/html; charset=utf-8');
+	require IA_ROOT . '/framework/version.inc.php';
+	echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
+	if (!empty(getenv('APP_ID')) && !empty(getenv('APP_SECRET')) && !empty(getenv('MYSQL_DATABASE')) && !empty($_SERVER['HTTP_SEC_FETCH_DEST']) && 'document' == $_SERVER['HTTP_SEC_FETCH_DEST']) {
+		header('Location: https://console.w7.cc/app/' . getenv('APP_ID') . '/founder/micro/installWe7');
+		exit;
+	} else {
+		$message = "如果你还没安装本程序,请运行<a href='" . (false === strpos($_SERVER['SCRIPT_NAME'], 'web') ? './install.php' : '../install.php') . "'> install.php 进入安装&gt;&gt; </a><br/><br/>";
+		$message .= "&nbsp;&nbsp;<a href='http://www.w7.cc' style='font-size:12px' target='_blank'>Power by W7 " . IMS_VERSION . ' &nbsp;微擎公众平台自助开源引擎</a>';
+		echo ierror_page($message);
+	}
+	exit();
+}
+unset($configfile, $config, $pdo_if_start);
+
+define('ATTACHMENT_ROOT', IA_ROOT . '/attachment/');
+error_reporting(0);
+define('DEVELOPMENT', $_W['config']['setting']['development'] == 1);
+if (STATUS_ON == $_W['config']['setting']['development']) {
+	$_W['config']['setting']['local_dev'] = STATUS_ON;
+	ini_set('display_errors', '1');
+	error_reporting(E_ALL ^ E_NOTICE);
+} else {
+	$_W['config']['setting']['local_dev'] = STATUS_OFF;
+}
+
+if (!in_array($_W['config']['setting']['cache'], array('mysql', 'memcache', 'redis', 'memcached'))) {
+	$_W['config']['setting']['cache'] = 'mysql';
+}
+load()->func('cache');
+
+if (function_exists('date_default_timezone_set')) {
+	date_default_timezone_set($_W['config']['setting']['timezone']);
+}
+if (!empty($_W['config']['setting']['memory_limit']) && function_exists('ini_get') && function_exists('ini_set')) {
+	if ($_W['config']['setting']['memory_limit'] != @ini_get('memory_limit')) {
+		@ini_set('memory_limit', $_W['config']['setting']['memory_limit']);
+	}
+}
+
+$_W['ispost'] = !empty($_SERVER['REQUEST_METHOD']) && 'POST' == strtoupper($_SERVER['REQUEST_METHOD']);
+
+if (MAGIC_QUOTES_GPC) {
+	$_GET = istripslashes($_GET);
+	$_POST = istripslashes($_POST);
+	$_COOKIE = istripslashes($_COOKIE);
+}
+
+$cplen = strlen($_W['config']['cookie']['pre']);
+foreach ($_COOKIE as $key => $value) {
+	if ($_W['config']['cookie']['pre'] == substr($key, 0, $cplen)) {
+		$_GPC[substr($key, $cplen)] = $value;
+	}
+}
+unset($cplen, $key, $value);
+
+$_GPC = array_merge($_GET, $_GPC, $_POST);
+$_GPC = ihtmlspecialchars($_GPC);
+
+$_W['siteurl'] = $urls['scheme'] . '://' . $urls['host'] . ((!empty($urls['port']) && '80' != $urls['port']) ? ':' . $urls['port'] : '') . $_W['script_name'] . '?' . http_build_query($_GET, '', '&');
+
+if (!$_W['isajax']) {
+	$input = file_get_contents('php://input');
+	if (!empty($input)) {
+		$__input = @json_decode($input, true);
+		if (!empty($__input)) {
+			$_GPC['__input'] = $__input;
+			$_W['isajax'] = true;
+		}
+	}
+	unset($input, $__input);
+}
+$_W['uniacid'] = $_W['uid'] = 0;
+
+setting_load();
+if (empty($_W['setting']['upload'])) {
+	$_W['setting']['upload'] = array_merge($_W['config']['upload']);
+}
+if (!empty($_W['setting']['local_version_info']['family']) || !empty($_W['setting']['site']['family'])) {
+	define('IMS_FAMILY', !empty($_W['setting']['local_version_info']['family']) ? $_W['setting']['local_version_info']['family'] : $_W['setting']['site']['family']);
+	define('IMS_VERSION', !empty($_W['setting']['local_version_info']['version']) ? $_W['setting']['local_version_info']['version'] : $_W['setting']['site']['version']);
+	define('IMS_RELEASE_DATE', !empty($_W['setting']['local_version_info']['release_date']) ? $_W['setting']['local_version_info']['release_date'] : $_W['setting']['site']['release']);
+} else {
+	require IA_ROOT . '/framework/version.inc.php';
+}
+$_W['os'] = Agent::deviceType();
+if (Agent::DEVICE_MOBILE == $_W['os']) {
+	$_W['os'] = 'mobile';
+} elseif (Agent::DEVICE_DESKTOP == $_W['os']) {
+	$_W['os'] = 'windows';
+} else {
+	$_W['os'] = 'unknown';
+}
+
+$_W['container'] = Agent::browserType();
+if (Agent::MICRO_MESSAGE_YES == Agent::isMicroMessage()) {
+	$_W['container'] = 'wechat';
+	if (Agent::MICRO_WXWORK_YES == Agent::isWxWork()) {
+		$_W['container'] = 'workwechat';
+	}
+} elseif (Agent::BROWSER_TYPE_ANDROID == $_W['container']) {
+	$_W['container'] = 'android';
+} elseif (Agent::BROWSER_TYPE_IPAD == $_W['container']) {
+	$_W['container'] = 'ipad';
+} elseif (Agent::BROWSER_TYPE_IPHONE == $_W['container']) {
+	$_W['container'] = 'iphone';
+} elseif (Agent::BROWSER_TYPE_IPOD == $_W['container']) {
+	$_W['container'] = 'ipod';
+} else {
+	$_W['container'] = 'unknown';
+}
+
+if ('wechat' == $_W['container'] || 'baidu' == $_W['container']) {
+	$_W['platform'] = 'account';
+}
+
+$controller = !empty($_GPC['c']) ? $_GPC['c'] : '';
+$action = !empty($_GPC['a']) ? $_GPC['a'] : '';
+$do = !empty($_GPC['do']) ? $_GPC['do'] : '';
+if (strtoupper(php_sapi_name()) != 'CLI') {
+	header('Content-Type: text/html; charset=' . $_W['charset']);
+}

BIN
framework/builtin/basic/icon.jpg


+ 1 - 0
framework/builtin/basic/index.html

xqd
@@ -0,0 +1 @@
+ 

BIN
framework/builtin/basic/preview.jpg


+ 22 - 0
framework/builtin/basic/processor.php

xqd
@@ -0,0 +1,22 @@
+<?php
+/**
+ * [WeEngine System] Copyright (c) 2014 WE7.CC
+ * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
+ */
+defined('IN_IA') or exit('Access Denied');
+
+class BasicModuleProcessor extends WeModuleProcessor {
+	public function respond() {
+		$rids = !is_array($this->rule) ? explode(',', $this->rule) : $this->rule;
+		$reply = table('basic_reply')->where(array('rid IN' => $rids))->orderby('RAND()')->get();
+		if (empty($reply)) {
+			return false;
+		}
+		$reply['content'] = htmlspecialchars_decode($reply['content']);
+		
+		$reply['content'] = str_replace(array('<br>', '&nbsp;'), array("\n", ' '), $reply['content']);
+		$reply['content'] = strip_tags($reply['content'], '<a>');
+
+		return $this->respText($reply['content']);
+	}
+}

BIN
framework/builtin/chats/icon.jpg


+ 1 - 0
framework/builtin/chats/index.html

xqd
@@ -0,0 +1 @@
+ 

+ 9 - 0
framework/builtin/chats/module.php

xqd
@@ -0,0 +1,9 @@
+<?php
+/**
+ * [WeEngine System] Copyright (c) 2014 WE7.CC
+ * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
+ */
+defined('IN_IA') or exit('Access Denied');
+
+class ChatsModule extends WeModule {
+}

BIN
framework/builtin/chats/preview.jpg


+ 67 - 0
framework/builtin/chats/processor.php

xqd
@@ -0,0 +1,67 @@
+<?php
+/**
+ * [WeEngine System] Copyright (c) 2014 WE7.CC
+ * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
+ */
+defined('IN_IA') or exit('Access Denied');
+
+class ChatsModuleProcessor extends WeModuleProcessor {
+	public $priority = 255;
+
+	public function begin($expire = 300) {
+		$this->beginContext($expire);
+		return true;
+	}
+
+	public function end() {
+		$this->respText('系统消息:公众号关闭了对话功能!');
+		$this->endContext();
+		return;
+	}
+
+	public function respond() {
+		global $_W;
+		$msgtype = $this->message['type'];
+		
+		$allow = array('text', 'image', 'location', 'link', 'trace');
+		if (!in_array($msgtype, $allow)) {
+			return $this->respText('抱歉,系统仅支持 文字,图片,地理位置,链接类型的消息!');
+		}
+		$close = 0;
+		if ('text' == $msgtype) {
+			$content = $this->message['content'];
+			if ('关闭' == $content) {
+				$content = '<span class="text-danger">系统消息:粉丝关闭了对话</span>';
+				$close = 1;
+			}
+		} elseif ('image' == $msgtype) {
+			$content = $this->message['picurl'];
+		} elseif ('location' == $msgtype) {
+			$content = iserializer(array(
+				'location_x' => $this->message['location_x'],
+				'location_y' => $this->message['location_y'],
+				'scale' => $this->message['scale'],
+			));
+		} elseif ('link' == $msgtype) {
+			$content = $this->message['url'];
+		}
+		if (!empty($content)) {
+			$insert = array(
+				'uniacid' => $_W['uniacid'],
+				'acid' => $_W['acid'],
+				'openid' => $_W['openid'],
+				'msgtype' => $msgtype,
+				'flag' => 2,
+				'content' => $content,
+				'createtime' => TIMESTAMP,
+			);
+			table('mc_chats_record')->fill($insert)->save();
+		}
+		$this->refreshContext(300);
+		if (1 == $close) {
+			$this->endContext();
+			return $this->respText('您成功关闭回话。');
+		}
+		return $this->respText('');
+	}
+}

+ 1 - 0
framework/builtin/core/index.html

xqd
@@ -0,0 +1 @@
+ 

+ 403 - 0
framework/builtin/core/module.php

xqd
@@ -0,0 +1,403 @@
+<?php
+/**
+ * [WeEngine System] Copyright (c) 2014 WE7.CC
+ * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
+ */
+defined('IN_IA') or exit('Access Denied');
+
+class CoreModule extends WeModule {
+	public $modules = array('basic', 'news', 'image', 'music', 'voice', 'video', 'wxcard', 'keyword', 'module', 'wxapp');
+	public $tablename = array(
+		'basic' => 'basic_reply',
+		'news' => 'news_reply',
+		'image' => 'images_reply',
+		'music' => 'music_reply',
+		'voice' => 'voice_reply',
+		'video' => 'video_reply',
+		'wxcard' => 'wxcard_reply',
+		'keyword' => 'basic_reply',
+		'wxapp' => 'wxapp_reply',
+	);
+	
+	private $options = array(
+		'basic' => true,
+		'news' => true,
+		'image' => true,
+		'music' => true,
+		'voice' => true,
+		'video' => true,
+		'wxcard' => true,
+		'keyword' => true,
+		'module' => true,
+		'wxapp' => true,
+	);
+	private $replies = array();
+
+	public function fieldsFormDisplay($rid = 0, $option = array()) {
+		global $_GPC, $_W, $setting_keyword;
+		load()->model('material');
+		load()->model('reply');
+		$module_name = empty($_GPC['module_name']) ? empty($_GPC['m']) ? '' : safe_gpc_string($_GPC['m']) : safe_gpc_string($_GPC['module_name']);
+		$replies = array();
+		switch ($_GPC['a']) {
+			case 'mass':
+				if (!empty($rid) && $rid > 0) {
+					$isexists = table('mc_mass_record')->getById($rid);
+				}
+				if (!empty($isexists['media_id']) && !empty($isexists['msgtype'])) {
+					$wechat_attachment = material_get($isexists['media_id']);
+					switch ($isexists['msgtype']) {
+						case 'news':
+							if (!empty($wechat_attachment['news'])) {
+								foreach ($wechat_attachment['news'] as &$item) {
+									$item['thumb_url'] = tomedia($item['thumb_url']);
+									$item['media_id'] = $isexists['media_id'];
+									$item['attach_id'] = $item['attach_id'];
+									$item['perm'] = $wechat_attachment['model'];
+								}
+								unset($item);
+							}
+							$replies['news'] = $wechat_attachment['news'];
+							break;
+						case 'image':
+							$replies['image'][0]['img_url'] = tomedia($wechat_attachment['attachment']);
+							$replies['image'][0]['mediaid'] = $isexists['media_id'];
+							break;
+						case 'voice':
+							$replies['voice'][0]['title'] = $wechat_attachment['filename'];
+							$replies['voice'][0]['mediaid'] = $isexists['media_id'];
+							break;
+						case 'video':
+							$replies['video'][0] = iunserializer($wechat_attachment['tag']);
+							$replies['video'][0]['mediaid'] = $isexists['media_id'];
+							break;
+					}
+				}
+				break;
+			
+			default:
+				if (!empty($rid)) {
+					$rule_rid = $rid;
+					if (in_array($module_name, array('welcome', 'default'))) {
+						$rule_rid = table('rule_keyword')->where(array('rid' => $rid))->getcolumn('rid');
+					}
+					$isexists = reply_single($rule_rid);
+				}
+				if ('special' == $module_name) {
+					$default_setting = uni_setting_load('default_message', $_W['uniacid']);
+					$default_setting = $default_setting['default_message'] ? $default_setting['default_message'] : array();
+					$reply_type = $default_setting[$_GPC['type']]['type'];
+					if (empty($reply_type)) {
+						if (!empty($default_setting[$_GPC['type']]['keyword'])) {
+							$reply_type = 'keyword';
+						}
+						if (!empty($default_setting[$_GPC['type']]['module'])) {
+							$reply_type = 'module';
+						}
+						if (empty($reply_type)) {
+							break;
+						}
+					}
+					if ('module' == $reply_type) {
+						$modules = explode(',', $default_setting[$_GPC['type']]['module']);
+						foreach ($modules as $k => $module_name) {
+							$replies['module'][$k]['name'] = $module_name;
+							$module_info = table('modules')->getByName($module_name);
+							$replies['module'][$k]['title'] = $module_info['title'];
+							if (!empty($module_info['logo'])) {
+								$replies['module'][$k]['icon'] = tomedia($module_info['logo']);
+							} else {
+								if (file_exists(IA_ROOT . '/addons/' . $module_info['name'] . '/custom-icon.jpg')) {
+									$replies['module'][$k]['icon'] = '../addons/' . $module_info['name'] . '/custom-icon.jgp';
+								} else {
+									$replies['module'][$k]['icon'] = '../addons/' . $module_info['name'] . '/icon.jpg';
+								}
+							}
+						}
+					} else {
+						$replies['keyword'][0]['name'] = empty($isexists['name']) ? '' : $isexists['name'];
+						$replies['keyword'][0]['content'] = $setting_keyword;
+						$replies['keyword'][0]['rid'] = $rid;
+						$replies['keyword'][0]['id'] = empty($isexists['keywords'][0]['id']) ? '' : $isexists['keywords'][0]['id'];
+					}
+					break;
+				}
+				if (!empty($isexists)) {
+					$module = $isexists['module'];
+					$module = 'images' == $module ? 'image' : $module;
+
+					
+					if ('reply' == safe_gpc_string($_GPC['a']) && (!empty($module_name) && 'keyword' == $module_name)) {
+						foreach ($this->tablename as $key => $tablename) {
+							if ('keyword' != $key) {
+								$replies[$key] = table($tablename)->where(array('rid' => $rid))->orderby('id')->getall();
+								switch ($key) {
+									case 'image':
+										foreach ($replies[$key] as &$img_value) {
+											$img = table('wechat_attachment')->getByMediaId($img_value['mediaid']);
+											$img_value['img_url'] = tomedia($img['attachment'], true);
+										}
+										unset($img_value);
+										break;
+									case 'news':
+										foreach ($replies[$key] as &$news_value) {
+											if (!empty($news_value) && !empty($news_value['media_id'])) {
+												$news_material = material_get($news_value['media_id']);
+												if (!is_error($news_material)) {
+													$news_value['attach_id'] = $news_material['id'];
+													$news_value['model'] = $news_material['model'];
+													$news_value['description'] = $news_material['news'][0]['digest'];
+													$news_value['thumb'] = tomedia($news_material['news'][0]['thumb_url']);
+												}
+											} else {
+												$news_value['thumb'] = tomedia($news_value['thumb']);
+											}
+										}
+										unset($news_value);
+										break;
+									case 'video':
+										foreach ($replies[$key] as &$video_value) {
+											$video_material = material_get($video_value['mediaid']);
+											$video_value['filename'] = $video_material['filename'];
+										}
+										unset($video_value);
+										break;
+									case 'voice':
+										foreach ($replies[$key] as &$voice_value) {
+											$voice_material = material_get($voice_value['mediaid']);
+											$voice_value['title'] = $voice_material['filename'];
+										}
+										unset($voice_value);
+										break;
+									case 'wxapp':
+										foreach ($replies[$key] as &$wxapp_value) {
+											$wxapp_material = material_get($wxapp_value['mediaid']);
+											$wxapp_value['thumb_url'] = empty($wxapp_material['attachment']) ? '' : $wxapp_material['attachment'];
+										}
+										unset($wxapp_value);
+										break;
+								}
+							}
+						}
+						
+					} else {
+						$replies['keyword'][0]['name'] = $isexists['name'];
+						$replies['keyword'][0]['rid'] = $rid;
+						$replies['keyword'][0]['content'] = $setting_keyword;
+						$replies['keyword'][0]['id'] = empty($isexists['keywords'][0]['id']) ? '' : $isexists['keywords'][0]['id'];
+					}
+				}
+				break;
+		}
+		if (!is_array($option)) {
+			$option = array();
+		}
+		$options = array_merge($this->options, $option);
+		include $this->template('display');
+	}
+
+	public function fieldsFormValidate($rid = 0) {
+		global $_GPC;
+		
+		$ifEmpty = 1;
+		$reply = '';
+		foreach ($this->modules as $key => $value) {
+			if ('' != safe_gpc_string($_GPC['reply']['reply_' . $value])) {
+				$ifEmpty = 0;
+			}
+			if (('music' == $value || 'video' == $value || 'wxcard' == $value || 'news' == $value || 'wxapp' == $value) && !empty($_GPC['reply']['reply_' . $value])) {
+				$reply = ltrim($_GPC['reply']['reply_' . $value], '{');
+				$reply = rtrim($reply, '}');
+				$reply = explode('},{', $reply);
+				foreach ($reply as &$val) {
+					$val = htmlspecialchars_decode('{' . $val . '}');
+				}
+				$this->replies[$value] = $reply;
+			} else {
+				$this->replies[$value] = htmlspecialchars_decode($_GPC['reply']['reply_' . $value], ENT_QUOTES);
+			}
+		}
+		if ($ifEmpty) {
+			return error(1, '必须填写有效的回复内容.');
+		}
+
+		return '';
+	}
+
+	public function fieldsFormSubmit($rid = 0) {
+		global $_GPC, $_W;
+		permission_check_account_user('platform_reply_keyword');
+		$delsql = '';
+		foreach ($this->modules as $k => $val) {
+			$tablename = $this->tablename[$val];
+			if (!empty($tablename)) {
+				table($tablename)->where(array('rid' => $rid))->delete();
+			}
+		}
+
+		foreach ($this->modules as $val) {
+			$replies = array();
+
+			$tablename = $this->tablename[$val];
+			if ($this->replies[$val]) {
+				if (is_array($this->replies[$val])) {
+					foreach ($this->replies[$val] as $value) {
+						$replies[] = json_decode($value, true);
+					}
+				} else {
+					$replies = explode(',', $this->replies[$val]);
+					foreach ($replies as  &$v) {
+						$v = json_decode($v);
+					}
+				}
+			}
+			switch ($val) {
+				case 'basic':
+					if (!empty($replies)) {
+						foreach ($replies as $reply) {
+							table($tablename)->fill(array('rid' => $rid, 'content' => $reply))->save();
+						}
+					}
+					break;
+				case 'news':
+					if (!empty($replies)) {
+						$parent_id = 0;
+						$attach_id = 0;
+						foreach ($replies as $k => $reply) {
+							if (!empty($attach_id) && $reply['attach_id'] == $attach_id) {
+								$reply['parent_id'] = $parent_id;
+							}
+							
+							if ('local' == $reply['model']) {
+								$reply['mediaid'] = $reply['attach_id'];
+							}
+							table($tablename)
+								->fill(array(
+									'rid' => $rid,
+									'parent_id' => $reply['parent_id'],
+									'title' => $reply['title'],
+									'thumb' => tomedia($reply['thumb']),
+									'createtime' => time(),
+									'media_id' => $reply['attach_id'],
+									'displayorder' => $reply['displayorder'],
+									'description' => $reply['description'],
+									'url' => $reply['url']
+								))
+								->save();
+							if (empty($attach_id) || $reply['attach_id'] != $attach_id) {
+								$parent_id = pdo_insertid();
+							}
+							$attach_id = $reply['attach_id'] ? $reply['attach_id'] : 0;
+						}
+					}
+					break;
+				case 'image':
+					if (!empty($replies)) {
+						foreach ($replies as $reply) {
+							table($tablename)
+								->fill(array(
+									'rid' => $rid,
+									'mediaid' => $reply,
+									'createtime' => time()
+								))
+								->save();
+						}
+					}
+					break;
+				case 'music':
+					if (!empty($replies)) {
+						foreach ($replies as $reply) {
+							table($tablename)
+								->fill(array(
+									'rid' => $rid,
+									'title' => $reply['title'],
+									'url' => $reply['url'],
+									'hqurl' => $reply['hqurl'],
+									'description' => $reply['description']
+								))
+								->save();
+						}
+					}
+					break;
+				case 'voice':
+					if (!empty($replies)) {
+						foreach ($replies as $reply) {
+							table($tablename)
+								->fill(array(
+									'rid' => $rid,
+									'mediaid' => $reply,
+									'createtime' => time()
+								))
+								->save();
+						}
+					}
+					break;
+				case 'video':
+					if (!empty($replies)) {
+						foreach ($replies as $reply) {
+							table($tablename)
+								->fill(array(
+									'rid' => $rid,
+									'mediaid' => $reply['mediaid'],
+									'title' => $reply['title'],
+									'description' => $reply['description'],
+									'createtime' => time()
+								))
+								->save();
+						}
+					}
+					break;
+				case 'wxcard':
+					if (!empty($replies)) {
+						foreach ($replies as $reply) {
+							table($tablename)
+								->fill(array(
+									'rid' => $rid,
+									'title' => $reply['title'],
+									'card_id' => $reply['mediaid'],
+									'cid' => $reply['cid'],
+									'brand_name' => $reply['brandname'],
+									'logo_url' => $reply['logo_url'],
+									'success' => $reply['success'],
+									'error' => $reply['error']
+								))
+								->save();
+						}
+					}
+					break;
+				case 'wxapp':
+					if (!empty($replies)) {
+						foreach ($replies as $reply) {
+							table($tablename)
+								->fill(array(
+									'rid' => $rid,
+									'title' => $reply['title'],
+									'appid' => $reply['appid'],
+									'pagepath' => $reply['pagepath'],
+									'mediaid' => $reply['mediaid'],
+									'createtime' => time()
+								))
+								->save();
+						}
+					}
+					break;
+			}
+		}
+
+		return true;
+	}
+
+	public function ruleDeleted($rid = 0) {
+		global $_W;
+		permission_check_account_user('platform_reply_keyword');
+		$reply_modules = array('basic', 'news', 'music', 'images', 'voice', 'video', 'wxcard', 'wxapp');
+		foreach ($this->tablename as $tablename) {
+			table($tablename)
+				->where(array(
+					'rid' => $rid,
+					'uniacid' => $_W['uniacid']
+				))
+				->delete();
+		}
+	}
+}

+ 199 - 0
framework/builtin/core/processor.php

xqd
@@ -0,0 +1,199 @@
+<?php
+/**
+ * [WeEngine System] Copyright (c) 2014 WE7.CC
+ * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
+ */
+defined('IN_IA') or exit('Access Denied');
+
+class CoreModuleProcessor extends WeModuleProcessor {
+	public function respond() {
+		$reply_type = $this->reply_type;
+		$key = array_rand($reply_type);
+		$type = $reply_type[$key];
+		switch ($type) {
+			case 'basic':
+				$result = $this->basic_respond();
+
+				return $this->respText($result);
+				break;
+			case 'images':
+				$result = $this->image_respond();
+
+				return $this->respImage($result);
+				break;
+			case 'music':
+				$result = $this->music_respond();
+
+				return $this->respMusic(array(
+						'Title' => $result['title'],
+						'Description' => $result['description'],
+						'MusicUrl' => $result['url'],
+						'HQMusicUrl' => $result['hqurl'],
+					));
+				break;
+			case 'news':
+				$result = $this->news_respond();
+
+				return $this->respNews($result);
+				break;
+			case 'voice':
+				$result = $this->voice_respond();
+
+				return $this->respVoice($result);
+				break;
+			case 'video':
+				$result = $this->video_respond();
+
+				return $this->respVideo(array(
+						'MediaId' => $result['mediaid'],
+						'Title' => $result['title'],
+						'Description' => $result['description'],
+					));
+				break;
+			case 'wxapp':
+				$result = $this->wxapp_respond();
+
+				return $this->respWxapp(array(
+					'Title' => $result['title'],
+					'Appid' => $result['appid'],
+					'PagePath' => $result['pagepath'],
+					'ThumbMediaId' => $result['mediaid'],
+				));
+				break;
+		}
+	}
+
+	private function basic_respond() {
+		$rids = !is_array($this->rule) ? explode(',', $this->rule) : $this->rule;
+		$reply = table('basic_reply')->where(array('rid IN' => $rids))->orderby('RAND()')->get();
+		if (empty($reply)) {
+			return false;
+		}
+		$reply['content'] = htmlspecialchars_decode($reply['content']);
+		
+		$reply['content'] = str_replace(array('<br>', '&nbsp;'), array("\n", ' '), $reply['content']);
+		$reply['content'] = strip_tags($reply['content'], '<a>');
+
+		return $reply['content'];
+	}
+
+	private function image_respond() {
+		global $_W;
+		$rid = $this->rule;
+		$mediaid = table('images_reply')->where(array('rid' => $rid))->orderby('RAND()')->getcolumn('mediaid');
+		if (empty($mediaid)) {
+			return false;
+		}
+
+		return $mediaid;
+	}
+
+	private function music_respond() {
+		global $_W;
+		$rid = $this->rule;
+		$item = table('music_reply')->where(array('rid' => $rid))->orderby('RAND()')->get();
+		if (empty($item['id'])) {
+			return false;
+		}
+
+		return $item;
+	}
+
+	private function news_respond() {
+		global $_W;
+		load()->model('material');
+		$rid = $this->rule;
+		$commends = table('news_reply')
+			->where(array('rid' => $rid, 'parent_id' => -1))
+			->orderby(array('displayorder' => 'DESC', 'id' => 'ASC'))
+			->limit(8)
+			->getall();
+		if (empty($commends)) {
+			
+			$main = table('news_reply')
+				->where(array(
+					'rid' => $rid,
+					'parent_id' => 0
+				))
+				->orderby('RAND()')
+				->get();
+			if (empty($main['id'])) {
+				return false;
+			}
+			$commends = table('news_reply')
+				->where(array('id' => $main['id']))
+				->whereor(array('parent_id' => $main['id']))
+				->orderby(array(
+					'displayorder' => 'ASC',
+					'id' => 'ASC'
+				))
+				->limit(8)
+				->getall();
+		}
+		if (empty($commends)) {
+			return false;
+		}
+		$news = array();
+		if (!empty($commends[0]['media_id'])) {
+			$news = material_build_reply($commends[0]['media_id']);
+		}
+		foreach ($commends as $key => $commend) {
+			$row = array();
+			if (!empty($commend['media_id'])) {
+				if (empty($news[$key]['url'])) {
+					$news[$key]['url'] = $this->createMobileUrl('detail', array('id' => $commend['id']));
+				}
+			} else {
+				$row['title'] = $commend['title'];
+				$row['description'] = $commend['description'];
+				!empty($commend['thumb']) && $row['picurl'] = tomedia($commend['thumb']);
+				$row['url'] = empty($commend['url']) ? $this->createMobileUrl('detail', array('id' => $commend['id'])) : $commend['url'];
+				$news[] = $row;
+			}
+		}
+
+		return $news;
+	}
+
+	private function voice_respond() {
+		global $_W;
+		$rid = $this->rule;
+		$mediaid = table('voice_reply')
+			->where(array('rid' => $rid))
+			->orderby('RAND()')
+			->getcolumn('mediaid');
+		if (empty($mediaid)) {
+			return false;
+		}
+
+		return $mediaid;
+	}
+
+	private function video_respond() {
+		global $_W;
+		$rid = $this->rule;
+		$item = table('video_reply')
+			->where(array('rid' => $rid))
+			->orderby('RAND()')
+			->get();
+		if (empty($item)) {
+			return false;
+		}
+
+		return $item;
+	}
+
+	private  function wxapp_respond() {
+		global $_W;
+		$rid = $this->rule;
+		$item = table('wxapp_reply')
+			->where(array('rid' => $rid))
+			->orderby('RAND()')
+			->get();
+		if (empty($item)) {
+			return false;
+		}
+
+		return $item;
+	}
+}

+ 156 - 0
framework/builtin/core/receiver.php

xqd
@@ -0,0 +1,156 @@
+<?php
+/**
+ * [WeEngine System] Copyright (c) 2014 WE7.CC
+ * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
+ */
+defined('IN_IA') or exit('Access Denied');
+class CoreModuleReceiver extends WeModuleReceiver {
+	public function receive() {
+		global $_W;
+		if ('subscribe' == $this->message['event'] && !empty($this->message['ticket'])) {
+			$sceneid = $this->message['scene'];
+			$acid = $this->acid;
+			$uniacid = $this->uniacid;
+			$ticket = trim($this->message['ticket']);
+			if (!empty($ticket)) {
+				$qr = table('qrcode')
+					->select(array('id', 'keyword', 'name', 'acid'))
+					->where(array(
+						'uniacid' => $uniacid,
+						'ticket' => $ticket
+					))
+					->getall();
+				if (!empty($qr)) {
+					if (1 != count($qr)) {
+						$qr = array();
+					} else {
+						$qr = $qr[0];
+					}
+				}
+			}
+			if (empty($qr)) {
+				$sceneid = trim($this->message['scene']);
+				$where = array(
+					'uniacid' => $_W['uniacid']
+				);
+				if (is_numeric($sceneid)) {
+					$where['qrcid'] = $sceneid;
+				} else {
+					$where['scene_str'] = $sceneid;
+				}
+				$qr = table('qrcode')
+					->select(array('id', 'keyword', 'name', 'acid'))
+					->where($where)
+					->get();
+			}
+			$insert = array(
+				'uniacid' => $_W['uniacid'],
+				'acid' => $qr['acid'],
+				'qid' => $qr['id'],
+				'openid' => $this->message['from'],
+				'type' => 1,
+				'qrcid' => intval($sceneid),
+				'scene_str' => $sceneid,
+				'name' => $qr['name'],
+				'createtime' => TIMESTAMP,
+			);
+			table('qrcode_stat')->fill($insert)->save();
+		} elseif ('SCAN' == $this->message['event']) {
+			$sceneid = trim($this->message['scene']);
+			$where = array('uniacid' => $_W['uniacid']);
+			if (is_numeric($sceneid)) {
+				$where['qrcid'] = $sceneid;
+			} else {
+				$where['scene_str'] = $sceneid;
+			}
+			$row = table('qrcode')
+				->select(array('id', 'keyword', 'name', 'acid'))
+				->where($where)
+				->get();
+			$insert = array(
+				'uniacid' => $_W['uniacid'],
+				'acid' => $row['acid'],
+				'qid' => $row['id'],
+				'openid' => $this->message['from'],
+				'type' => 2,
+				'qrcid' => intval($sceneid),
+				'scene_str' => $sceneid,
+				'name' => $row['name'],
+				'createtime' => TIMESTAMP,
+			);
+			
+			if ($_W['setting']['qr_status']['status'] == 1) {
+				$qrLog = table('qrcode_stat')->where(array('uniacid' => $_W['uniacid'], 'qid' => $row['id'], 'openid' => $this->message['from']))->get();
+				if (empty($qrLog)) table('qrcode_stat')->fill($insert)->save();
+			} else {
+				table('qrcode_stat')->fill($insert)->save();
+			}
+
+		} elseif ('user_get_card' == $this->message['event']) {
+			$sceneid = $this->message['outerid'];
+			$row = table('qrcode')->where(array('qrcid' => $sceneid))->get();
+			if (!empty($row)) {
+				$insert = array(
+					'uniacid' => $_W['uniacid'],
+					'acid' => $row['acid'],
+					'qid' => $row['id'],
+					'openid' => $this->message['from'],
+					'type' => 2,
+					'qrcid' => $sceneid,
+					'scene_str' => $sceneid,
+					'name' => $row['name'],
+					'createtime' => TIMESTAMP,
+				);
+				table('qrcode_stat')->fill($insert)->save();
+			}
+		}
+		if ('subscribe' == $this->message['event'] && !empty($_W['account']) && ($_W['account']['level'] == ACCOUNT_SERVICE_VERIFY || $_W['account']['level'] == ACCOUNT_SUBSCRIPTION_VERIFY)) {
+			$account_obj = WeAccount::createByUniacid();
+			$userinfo = $account_obj->fansQueryInfo($this->message['from']);
+			if (!is_error($userinfo) && !empty($userinfo) && !empty($userinfo['subscribe'])) {
+				load()->model('mc');
+				$fan = mc_fansinfo($this->message['from'], 0 , $_W['uniacid']);
+				$userinfo['nickname'] = $fan['nickname'];
+				$fans = array(
+					'unionid' => $userinfo['unionid'],
+				);
+				if (empty($fan['tag'])) {
+					$fans['tag'] = base64_encode(iserializer($userinfo));
+				}
+				table('mc_mapping_fans')
+					->where(array('openid' => $this->message['from']))
+					->fill($fans)
+					->save();
+				$mc_fans_tag_table = table('mc_fans_tag');
+				$mc_fans_tag_fields = mc_fans_tag_fields();
+				$fans_tag_update_info = array();
+				foreach ($userinfo as $fans_field_key => $fans_field_info) {
+					if (in_array($fans_field_key, array_keys($mc_fans_tag_fields))) {
+						$fans_tag_update_info[$fans_field_key] = $fans_field_info;
+					}
+				}
+				$fans_tag_update_info['tagid_list'] = iserializer($fans_tag_update_info['tagid_list']);
+				$fans_tag_update_info['uniacid'] = $_W['uniacid'];
+				$fans_tag_update_info['fanid'] = $fan['fanid'];
+				$fans_tag_exists = $mc_fans_tag_table->getByOpenid($fans_tag_update_info['openid']);
+				if (!empty($fans_tag_exists)) {
+					unset($fans_tag_update_info['headimgurl']);
+					table('mc_fans_tag')
+						->where(array('openid' => $fans_tag_update_info['openid']))
+						->fill($fans_tag_update_info)
+						->save();
+				} else {
+					table('mc_fans_tag')->fill($fans_tag_update_info)->save();
+				}
+				$uid = !empty($_W['member']['uid']) ? $_W['member']['uid'] : $this->message['from'];
+				if (!empty($uid)) {
+					$member = array();
+					if (!empty($userinfo['nickname'])) {
+						$member['nickname'] = $userinfo['nickname'];
+					}
+					mc_update($uid, $member);
+				}
+			}
+		}
+	}
+}

+ 282 - 0
framework/builtin/core/site.php

xqd
@@ -0,0 +1,282 @@
+<?php
+/**
+ * [WeEngine System] Copyright (c) 2014 WE7.CC
+ * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
+ */
+defined('IN_IA') or exit('Access Denied');
+
+class CoreModuleSite extends WeModuleSite {
+	public function doMobilePaymethod() {
+		global $_W, $_GPC;
+		$params = array(
+			'fee' => floatval($_GPC['fee']),
+			'tid' => safe_gpc_string($_GPC['tid']),
+			'module' => safe_gpc_string($_GPC['module']),
+		);
+		if (empty($params['tid']) || empty($params['fee']) || empty($params['module'])) {
+			message(error(1, '支付参数不完整'));
+		}
+		
+		if ($params['fee'] <= 0) {
+			$notify_params = array(
+				'form' => 'return',
+				'result' => 'success',
+				'type' => '',
+				'tid' => $params['tid'],
+			);
+			$site = WeUtility::createModuleSite($params['module']);
+			$method = 'payResult';
+			if (method_exists($site, $method)) {
+				$site->$method($notify_params);
+				message(error(-1, '支付成功'));
+			}
+		}
+		$log = table('core_paylog')
+			->searWithUniacid($_W['uniacid'])
+			->SearWithModule($params['module'])
+			->searWithTid($params['tid'])
+			->get();
+		if (empty($log)) {
+			$log = array(
+				'uniacid' => $_W['uniacid'],
+				'acid' => $_W['acid'],
+				'openid' => $_W['member']['uid'],
+				'module' => $params['module'],
+				'tid' => $params['tid'],
+				'fee' => $params['fee'],
+				'card_fee' => $params['fee'],
+				'status' => '0',
+				'is_usecard' => '0',
+			);
+			table('core_paylog')->fill($log)->save();
+		}
+		if ('1' == $log['status']) {
+			message(error(1, '订单已经支付'));
+		}
+		$setting = uni_setting($_W['uniacid'], array('payment', 'creditbehaviors'));
+		if (!is_array($setting['payment'])) {
+			message(error(1, '暂无有效支付方式'));
+		}
+		$pay = $setting['payment'];
+		if (empty($_W['member']['uid'])) {
+			$pay['credit']['switch'] = false;
+		}
+		if (!empty($pay['credit']['switch'])) {
+			$credtis = mc_credit_fetch($_W['member']['uid']);
+		}
+
+		include $this->template('pay');
+	}
+
+	
+	public function doMobilePay() {
+		global $_W, $_GPC;
+
+		$moduels = uni_modules();
+		$params = $_POST;
+
+		if (empty($params) || !array_key_exists($params['module'], $moduels)) {
+			message(error(1, '模块不存在'), '', 'ajax', true);
+		}
+
+		$setting = uni_setting($_W['uniacid'], 'payment');
+		$dos = array();
+		if (!empty($setting['payment']['credit']['pay_switch'])) {
+			$dos[] = 'credit';
+		}
+		if (!empty($setting['payment']['alipay']['pay_switch'])) {
+			$dos[] = 'alipay';
+		}
+		if (!empty($setting['payment']['wechat']['pay_switch'])) {
+			$dos[] = 'wechat';
+		}
+		if (!empty($setting['payment']['delivery']['pay_switch'])) {
+			$dos[] = 'delivery';
+		}
+		if (!empty($setting['payment']['unionpay']['pay_switch'])) {
+			$dos[] = 'unionpay';
+		}
+		if (!empty($setting['payment']['baifubao']['pay_switch'])) {
+			$dos[] = 'baifubao';
+		}
+		$type = in_array($params['method'], $dos) ? $params['method'] : '';
+		if (empty($type)) {
+			message(error(1, '暂无有效支付方式,请联系商家'), '', 'ajax', true);
+		}
+		$moduleid = table('modules')
+			->where(array('name' => $params['module']))
+			->getcolumn('mid');
+		$moduleid = empty($moduleid) ? '000000' : sprintf('%06d', $moduleid);
+		$uniontid = date('YmdHis') . $moduleid . random(8, 1);
+
+		$paylog = table('core_paylog')
+			->where(array('uniacid' => $uniacid))
+			->searchWithModule($params['module'])
+			->searchWithTid($params['tid'])
+			->get();
+		if (empty($paylog)) {
+			$paylog = array(
+				'uniacid' => $_W['uniacid'],
+				'acid' => $_W['acid'],
+				'openid' => $_W['member']['uid'],
+				'type' => $type,
+				'module' => $params['module'],
+				'tid' => $params['tid'],
+				'uniontid' => $uniontid,
+				'fee' => $params['fee'],
+				'card_fee' => $params['fee'],
+				'status' => '0',
+				'is_usecard' => '0',
+			);
+			table('core_paylog')->fill($paylog)->save();
+			$paylog['plid'] = pdo_insertid();
+		}
+		if (!empty($paylog) && '0' != $paylog['status']) {
+			message(error(1, '这个订单已经支付成功, 不需要重复支付.'), '', 'ajax', true);
+		}
+		if (!empty($paylog) && empty($paylog['uniontid'])) {
+			table('core_paylog')
+				->where(array('plid' => $paylog['plid']))
+				->fill(array('uniontid' => $uniontid))
+				->save();
+		}
+		$paylog['title'] = $params['title'];
+		if (intval($_GPC['iswxapp'])) {
+			message(error(2, $_W['siteroot'] . "app/index.php?i={$_W['uniacid']}&c=wxapp&a=home&do=go_paycenter&title={$params['title']}&plid={$paylog['plid']}"), '', 'ajax', true);
+		}
+
+		if ('wechat' == $params['method']) {
+			if (!empty($params['goods_tag'])) {
+				$paylog['goods_tag'] = $params['goods_tag'];
+			}
+			return $this->doMobilePayWechat($paylog);
+		} elseif ('alipay' == $params['method']) {
+			return $this->doMobilePayAlipay($paylog);
+		} else {
+			$params['tid'] = $paylog['plid'];
+			$sl = base64_encode(json_encode($params));
+			$auth = sha1($sl . $_W['uniacid'] . $_W['config']['setting']['authkey']);
+			message(error(0, $_W['siteroot'] . "/payment/{$type}/pay.php?i={$_W['uniacid']}&auth={$auth}&ps={$sl}"), '', 'ajax', true);
+			exit();
+		}
+	}
+
+	private function doMobilePayWechat($paylog = array()) {
+		global $_W;
+		load()->model('payment');
+
+		table('core_paylog')
+			->where(array('plid' => $paylog['plid']))
+			->fill(array(
+				'openid' => $_W['openid'],
+				'tag' => iserializer(array('acid' => $_W['acid'], 'uid' => $_W['member']['uid'])),
+			))
+			->save();
+		$_W['uniacid'] = $paylog['uniacid'];
+
+		$setting = uni_setting($_W['uniacid'], array('payment'));
+		$wechat_payment = $setting['payment']['wechat'];
+
+		$account = table('account_wechats')
+			->where(array('acid' => $wechat_payment['account']))
+			->get();
+		$wechat_payment['appid'] = $account['key'];
+		$wechat_payment['secret'] = $account['secret'];
+
+		$params = array(
+			'tid' => $paylog['tid'],
+			'fee' => $paylog['card_fee'],
+			'user' => $paylog['openid'],
+			'title' => urldecode($paylog['title']),
+			'uniontid' => $paylog['uniontid'],
+			'goods_tag' => empty($paylog['goods_tag']) ? '' : $paylog['goods_tag'],
+		);
+		if (PAYMENT_WECHAT_TYPE_SERVICE == intval($wechat_payment['switch']) || PAYMENT_WECHAT_TYPE_BORROW == intval($wechat_payment['switch'])) {
+			
+			if (PAYMENT_WECHAT_TYPE_SERVICE == intval($wechat_payment['switch'])) {
+				$wechat_payment['sub_appid'] = $wechat_payment['appid'];
+			}
+			$params['tid'] = $paylog['plid'];
+			
+			$params['title'] = urlencode($params['title']);
+			$sl = base64_encode(json_encode($params));
+			$auth = sha1($sl . $paylog['uniacid'] . $_W['config']['setting']['authkey']);
+
+			$callback = urlencode($_W['siteroot'] . "payment/wechat/pay.php?i={$_W['uniacid']}&auth={$auth}&ps={$sl}");
+			$proxy_pay_account = payment_proxy_pay_account();
+			if (!is_error($proxy_pay_account)) {
+				$forward = $proxy_pay_account->getOauthCodeUrl($callback, 'we7sid-' . $_W['session_id']);
+				
+				message(error(2, $forward . '##auto'), $forward, 'ajax');
+				exit;
+			}
+		} else {
+			unset($wechat_payment['sub_mch_id']);
+			$wechat_payment_params = wechat_build($params, $wechat_payment);
+		}
+		if (is_error($wechat_payment_params)) {
+			message($wechat_payment_params, '', 'ajax', true);
+		} else {
+			message(error(0, $wechat_payment_params), '', 'ajax', true);
+		}
+	}
+
+	private function doMobilePayAlipay($paylog = array()) {
+		global $_W;
+
+		load()->model('payment');
+		load()->func('communication');
+
+		$_W['uniacid'] = $paylog['uniacid'];
+
+		$setting = uni_setting($_W['uniacid'], array('payment'));
+		$params = array(
+			'tid' => $paylog['tid'],
+			'fee' => $paylog['card_fee'],
+			'user' => $paylog['openid'],
+			'title' => urldecode($paylog['title']),
+			'uniontid' => $paylog['uniontid'],
+		);
+		$alipay_payment_params = alipay_build($params, $setting['payment']['alipay']);
+		if ($alipay_payment_params['url']) {
+			message(error(0, $alipay_payment_params['url']), '', 'ajax', true);
+			exit();
+		}
+	}
+
+	public function doMobileDetail() {
+		global $_W, $_GPC;
+		$id = intval($_GPC['id']);
+		$row = table('news_reply')->getById($id);
+		$createtime = $row['createtime'];
+		if (!empty($row['url'])) {
+			header('Location: ' . $row['url']);
+			exit;
+		}
+		
+		if (!empty($row['media_id']) && 0 != intval($row['media_id'])) {
+			$row = table('wechat_news')
+				->where(array(
+					'attach_id' => $row['media_id'],
+					'displayorder' => $row['displayorder']
+				))
+				->get();
+			$row['createtime'] = $createtime;
+			if (!empty($row['content_source_url'])) {
+				header('Location: ' . $row['content_source_url']);
+				exit;
+			}
+		}
+		$row = istripslashes($row);
+		$title = $row['title'];
+		
+		if ('android' == $_W['os'] && 'wechat' == $_W['container'] && $_W['account']['account']) {
+			$subscribeurl = "weixin://profile/{$_W['account']['account']}";
+		} else {
+			$subscribeurl = table('account_wechats')
+				->where(array('uniacid' => intval($_W['uniacid'])))
+				->getcolumn('subscribeurl');
+		}
+		include $this->template('detail');
+	}
+}

+ 844 - 0
framework/builtin/core/template/display.html

xqd
@@ -0,0 +1,844 @@
+<div class="panel we7-panel panel-reply">
+	<div class="panel-heading">
+		{if $_GPC['a'] == 'qr'}二维码触发的关键字
+		{elseif $_GPC['a'] == 'mass'}群发内容
+		{else}
+			{if $_GPC['c'] == 'mc' && $_GPC['a'] == 'chats'}发送聊天内容{else}触发后回复内容{/if}
+			{if $_GPC['a'] == 'reply' && !empty($_GPC['m']) && $_GPC['m'] == 'keyword'}<span class="pull-right color-gray">添加多条回复内容时, 随机回复其中一条</span>{/if}
+		{/if}
+	</div>
+	<div class="panel-body we7-padding">
+	<input type="hidden" name="reply[reply_basic]" value="">
+	<input type="hidden" name="reply[reply_news]" value="">
+	<input type="hidden" name="reply[reply_image]" value="">
+	<input type="hidden" name="reply[reply_music]" value="">
+	<input type="hidden" name="reply[reply_voice]" value="">
+	<input type="hidden" name="reply[reply_video]" value="">
+	<input type="hidden" name="reply[reply_keyword]" value="">
+	<input type="hidden" name="reply[reply_module]" value="">
+	<input type="hidden" name="reply[reply_wxapp]" value="">
+		<ul class="keywords-list">
+		</ul>
+		<div class="we7-select-msg">
+			<ul class="tab-navs">
+				<li class="tab-nav tab-appmsg active {if $options['news']}hidden{/if}">
+					<a href="javascript:void(0);"{if $_GPC['a'] == 'mass'} onclick="select_mediaid('news', 'wx')"{else} onclick="select_mediaid('news')"{/if}>
+						<img src="./resource/images/reply/appmsg-icon.png" alt="">
+						<span class="msg-tab-title">图文</span>
+					</a>
+				</li>
+				<li class="tab-nav tab-text {if $options['basic']}hidden{/if}">
+					<a href="javascript:void(0);" onclick="select_mediaid('basic');">
+						<img src="./resource/images/reply/text-icon.png" alt="">
+						</i><span class="msg-tab-title">文字</span>
+					</a>
+				</li>
+				<li class="tab-nav tab-img {if $options['image']}hidden{/if}">
+					<a href="javascript:void(0);" onclick="select_mediaid('image');">
+						<img src="./resource/images/reply/image-icon.png" alt="">
+						<span class="msg-tab-title">微信图片</span>
+					</a>
+				</li>
+				<li class="tab-nav tab-audio {if $options['music']}hidden{/if}">
+					<a href="javascript:void(0);" onclick="select_mediaid('music');">
+						<img src="./resource/images/reply/music-icon.png" alt="">
+						<span class="msg-tab-title">音乐</span>
+					</a>
+				</li>
+				<li class="tab-nav tab-audio {if $options['voice']}hidden{/if}">
+					<a href="javascript:void(0);" onclick="select_mediaid('voice');">
+						<img src="./resource/images/reply/radio-icon.png" alt="">
+						<span class="msg-tab-title">语音</span>
+					</a>
+				</li>
+				<li class="tab-nav tab-video {if $options['video']}hidden{/if}">
+					<a href="javascript:void(0);" onclick="select_mediaid('video');">
+						<img src="./resource/images/reply/vedio-icon.png" alt="">
+						<span class="msg-tab-title">视频</span>
+					</a>
+				</li>
+				<li class="tab-nav tab-video {if $options['wxapp']}hidden{/if}">
+					<a href="javascript:void(0);" onclick="select_mediaid('wxapp');">
+						<img src="./resource/images/reply/wxapp-icon.png" alt="">
+						<span class="msg-tab-title">小程序</span>
+					</a>
+				</li>
+				<li class="tab-nav tab-cardmsg {if $options['keyword']}hidden{/if}">
+					<a href="javascript:void(0);" onclick="select_mediaid('keyword');">
+						<img src="./resource/images/reply/keyword-icon.png" alt="">
+						<span class="msg-tab-title">{if !empty($_GPC['m']) && $_GPC['m'] == 'welcome'}匹配{else}触发{/if}关键字</span>
+					</a>
+				</li>
+				<li class="tab-nav tab-cardmsg {if $options['module']}hidden{/if}">
+					<a href="javascript:void(0);" onclick="select_mediaid('module');">
+						<img src="./resource/images/reply/module-icon.png" alt="">
+						<span class="msg-tab-title">模块</span>
+					</a>
+				</li>
+			</ul>
+		</div>
+	</div>
+</div>
+<script>
+	var action = "{php echo empty($_GPC['a']) ? '' : $_GPC['a']}";
+	var m = "{php echo empty($_GPC['m']) ? '' : $_GPC['m']}";
+
+	//删除已选素材
+	var delmedia = function(type, ele) {
+		var oldVal = $(':hidden[name="reply[reply_'+type+']"]').val();
+		var newVal;
+		var media = $(ele).attr('data-media');
+		switch(type) {
+			case 'basic':
+				var middleVal = oldVal.split(',');
+				newVal = angular.copy(middleVal);
+				angular.forEach(middleVal, function(val, key) {
+					middleVal[key] = htmlEncode(angular.toJson(val));
+				});
+				var index = _.indexOf(middleVal, htmlEncode(angular.toJson(media)));
+				newVal = _.without(newVal, newVal[index]);
+				$(':hidden[name="reply[reply_'+type+']"]').val(newVal);
+				break;
+			case 'image':
+				var middleVal = oldVal.split(',');
+				newVal = angular.copy(middleVal);
+				newVal = _.without(newVal, '"' + media + '"');
+				$(':hidden[name="reply[reply_'+type+']"]').val(newVal);
+				break;
+			case 'news':
+				var middleVal = JSON.parse('[' +oldVal + ']' );
+				newVal = angular.copy(middleVal);
+				var findKey = false
+				angular.forEach(middleVal, function(val, key){
+					if(!findKey && val.mediaid == media ) {
+						findKey = key
+					}
+				});
+				newVal.splice(findKey, 1)
+				angular.forEach(newVal, function(val, key) {
+					newVal[key] = angular.toJson(val)
+				});
+				$(':hidden[name="reply[reply_'+type+']"]').val(newVal);
+				break;
+			case 'music':
+				var middleVal = JSON.parse('[' +oldVal + ']' );
+				newVal = angular.copy(middleVal);
+				var findKey = false
+				angular.forEach(middleVal, function(val, key){
+					if(!findKey && val.url == media ) {
+						findKey = key
+					}
+				});
+				newVal.splice(findKey, 1)
+				angular.forEach(newVal, function(val, key) {
+					newVal[key] = angular.toJson(val)
+				});
+				$(':hidden[name="reply[reply_'+type+']"]').val(newVal);
+				break;
+			case 'video':
+				
+				var middleVal = JSON.parse('[' +oldVal + ']' );
+				newVal = angular.copy(middleVal);
+				var findKey = false
+				angular.forEach(middleVal, function(val, key){
+					if(!findKey && val.mediaid == media ) {
+						findKey = key
+					}
+				});
+				newVal.splice(findKey, 1)
+				angular.forEach(newVal, function(val, key) {
+					newVal[key] = angular.toJson(val)
+				});
+				$(':hidden[name="reply[reply_'+type+']"]').val(newVal);
+				break;
+			case 'voice':
+				var middleVal = oldVal.split(',');
+				newVal = angular.copy(middleVal);
+				newVal = _.without(newVal, '"' + media + '"');
+				$(':hidden[name="reply[reply_'+type+']"]').val(newVal);
+				break;
+			case 'wxapp':
+				oldVal = JSON.parse('[' +oldVal + ']' )
+				oldVal.splice(media, 1)
+				var newVal = []
+				for(var i in oldVal) {
+					newVal.push(angular.toJson(oldVal[i]))
+				}
+				$(':hidden[name="reply[reply_'+type+']"]').val(newVal);
+				break;
+			case 'keyword':
+				oldVal = oldVal.split(',');
+				index = _.indexOf(oldVal, media);
+				oldVal.splice(index, 1);
+				$(':hidden[name="reply[reply_'+type+']"]').val(oldVal);
+				break;
+			case 'module':
+				oldVal = oldVal.split(',');
+				index = _.indexOf(oldVal, media);
+				oldVal.splice(index, 1);
+				$(':hidden[name="reply[reply_'+type+']"]').val(oldVal);
+				break;
+		}
+		//显示隐藏-start
+		if((action == 'qr' || action == 'mass' || m == 'special' || m == 'welcome' || m == 'default') && $(':hidden[name="reply[reply_'+type+']"]').val().length == 0) {
+			$('.we7-select-msg').removeClass('hide');
+		}
+		//显示隐藏-end
+		$(ele).parent().parent('.del-'+type+'-media').parent('li').remove();
+	};
+
+	window.select_mediaid = function(type, otherVal){
+		var draft = "{php echo !empty($_GPC['a']) && $_GPC['a'] == 'mass' ? true : false}";
+		var option = {
+			type: type,
+			isWechat : type != 'music' || draft, // 默认显示微信
+			needType : 3, //  除了图文 其他只能微信
+			otherVal : otherVal,//
+			showType: type == 'news' && !draft ? 3 : (type != 'music' && !draft ? 1 : 2), // 只显示微信素材
+			others: {
+				image: {
+					needType : 1
+				},
+				video : {
+					needType : 1
+				},
+				voice : {
+					needType : 3
+				}
+			},
+			is_draft : draft,
+			is_wx : draft && type == 'news' ? 1 : 0,
+			is_local : draft && type == 'news' ? 1 : 0,
+			is_index : draft && type == 'news' ? 2 : 0,
+		};
+		if (type == 'module'){
+			document.cookie = "special_reply_type={php echo empty($_GPC['type']) ? '' : $_GPC['type']}";
+		}
+		util.material(function(material){
+			var replyVal = [];
+			$(':hidden[name="reply[reply_'+type+']"]').val() == '' ? '' : replyVal.push($(':hidden[name="reply[reply_'+type+']"]').val());
+			if (type == 'basic') {
+				if (angular.isDefined(otherVal)) {
+					var editmedia = $(".del-basic-media");
+					for (var i = 0; i < editmedia.length; i++) {
+						if (htmlEncode($(editmedia.get(i)).find('.edit-gray').data('media')) == htmlEncode(angular.toJson(otherVal))) {
+							var inputVal = $(':hidden[name="reply[reply_'+type+']"]').val();
+							var inputValArr = inputVal.split(',');
+							var middleVal = angular.copy(inputValArr);
+							angular.forEach(inputValArr, function(val, key) {
+								inputValArr[key] = htmlEncode(val);
+							});
+							var index = _.indexOf(inputValArr, htmlEncode(angular.toJson(otherVal)));
+							material.content = material.content.replace(/,/g, ',');
+							middleVal[index] = angular.toJson(material.content);
+							replyVal = middleVal.join(',');
+							$(':hidden[name="reply[reply_'+type+']"]').val(replyVal);
+							$(editmedia.get(i)).html(
+								'	<div class="desc">'+
+								'		<div class="media-content">'+
+								'			<span data-toggle="tooltip" data-placement="bottom" title="'+htmlEncode(material.content)+'">'+htmlEncode(cutStr(material.content,60))+
+								'			</span>'+
+								'		</div>'+
+								'	</div>'+
+								'	<div class="opr">'+
+								'		<a href="javascript:;" data-media="'+htmlEncode(angular.toJson(material.content))+'" class="edit-gray" onclick="select_mediaid(\'basic\', '+htmlEncode(angular.toJson(material.content))+')">编辑</a>'+
+								'		<a href="javascript:;" data-media="'+htmlEncode(angular.toJson(material.content))+'" class="del-gray" onclick="delmedia(\''+type+'\', this)">删除</a>'+
+								'	</div>'
+							);
+							break;
+						}
+					}
+				} else {
+					if($.trim(material.content).length == 0) {
+						return false;
+					}
+					material.content = material.content.replace(/,/g, ',');
+					replyVal.push(angular.toJson(material.content));
+					$(':hidden[name="reply[reply_'+type+']"]').val(replyVal);
+					$('.keywords-list').append(
+						'<li>'+
+						'<div class="del-'+type+'-media">'+
+						'	<div class="desc">'+
+						'		<div class="media-content">'+
+						'			<span data-toggle="tooltip" data-placement="bottom" title="'+htmlEncode(material.content)+'">'+htmlEncode(cutStr(material.content,60))+'</span>'+
+						'		</div>'+
+						'	</div>'+
+						'	<div class="opr">'+
+						'		<a href="javascript:;" data-media="'+htmlEncode(angular.toJson(material.content))+'" class="edit-gray" onclick="select_mediaid(\'basic\', '+htmlEncode(angular.toJson(material.content))+')">编辑</a>'+
+						'		<a href="javascript:;" data-media="'+htmlEncode(angular.toJson(material.content))+'" class="del-gray" onclick="delmedia(\''+type+'\', this)">删除</a>'+
+						'	</div>'+
+						'</div>'+
+						'</li>'
+					);
+				}
+			} else if(type == 'keyword') {
+				if($.trim(material.id).length == 0) {
+					return false;
+				}
+				replyVal.push(material.id);
+				$(':hidden[name="reply[reply_'+type+']"]').val(replyVal);
+				var keywords = [];
+				for(var i = 0; i < material.length; i++) {
+					keywords += '&nbsp;&nbsp;' + material.content;
+				}
+				$('.keywords-list').append(
+					'<li>'+
+					'<div class="del-'+type+'-media">'+
+					'	<div class="desc">'+
+					'		<div class="media-content">'+
+					'				<a class="title-wrp" href="javascript:;">'+
+					'					<span class="title">[关键字]'+material.content+'</span>'+
+					'				</a>'+
+					'				<p class="desc"><a href="javascript:;" class="appmsg-desc">'+keywords+'</a></p>'+
+					'		</div>'+
+					'	</div>'+
+					'	<div class="opr">'+
+					// '		<a href="./index.php?c=platform&a=reply&do=post&m=keyword&rid=' + material.rid + '" target="_blank" class="del-gray">编辑</a> '  +
+					'		<a href="javascript:;" data-media="'+material.content+'" class="del-gray" onclick="delmedia(\''+type+'\', this)">删除</a>'+
+					'	</div>'+
+					'</div>'+
+					'</li>'
+				);
+
+			} else if(type == 'module') {
+				if($.trim(material.name).length == 0) {
+					return false;
+				}
+				$('.keywords-list').append(
+						'<li>'+
+						'<div class="del-'+type+'-media">'+
+						'	<div class="desc">'+
+						'		<div class="media-content">'+
+						'			<div class="appmsgSendedItem">'+
+						'				<a class="title-wrp" href="javascript:;">'+
+						'					 <span class="icon cover" style="background-image:url('+material.icon+');"></span>'+
+						'					<span class="title">[模块]'+material.title+'</span>'+
+						'				</a>'+
+						'			</div>'+
+						'		</div>'+
+						'	</div>'+
+						'	<div class="opr">'+
+						'		<a href="javascript:;" data-media="'+material.name+'" class="del-gray" onclick="delmedia(\''+type+'\', this)">删除</a>'+
+						'	</div>'+
+						'</div>'+
+						'</li>'
+				);
+				replyVal.push(material.name);
+				$(':hidden[name="reply[reply_'+type+']"]').val(replyVal);
+			} else {
+				if(type != 'music' && type != 'wxapp' && ($.trim(material.media_id).length == 0 && $.trim(material.article_id).length == 0) && !(type == 'news' && material.model == 'local')) {
+					return false;
+				};
+				switch(type) {
+					case 'image':
+						replyVal.push(angular.toJson(material.media_id));
+
+						$('.keywords-list').append(
+							'<li>'+
+							'<div class="del-'+type+'-media">'+
+							'	<div class="desc">'+
+							'		<div class="media-content">'+
+							'			<div class="appmsgSendedItem">'+
+							'				<a class="title-wrp" href="javascript:;">'+
+							'					 <span class="icon cover" style="background-image:url('+material.url+');"></span>'+
+							'					<span class="title">[图片]</span>'+
+							'				</a>'+
+							'			</div>'+
+							'		</div>'+
+							'	</div>'+
+							'	<div class="opr">'+
+							'		<a href="javascript:;" data-media="'+material.media_id+'" class="del-gray" onclick="delmedia(\''+type+'\', this)">删除</a>'+
+							'	</div>'+
+							'</div>'+
+							'</li>'
+						);
+						break;
+					case 'news':
+					replyVal.push(angular.toJson({
+						title: material.items[0].title,
+						author: material.items[0].author,
+						description: material.items[0].digest,
+						thumb: material.items[0].thumb_url,
+						url: material.items[0].content_source_url ? material.items[0].content_source_url : material.items[0].url,
+						createtime: material.items[0].createtime,
+						displayorder: material.items[0].displayorder ? material.items[0].displayorder : 0,
+						mediaid: material.media_id,
+						articleid: material.article_id,
+						model: material.model,
+						attach_id: material.items[0].attach_id
+					}));
+						$('.keywords-list').append(
+							'<li>'+
+							'<div class="del-'+type+'-media">'+
+							'	<div class="desc">'+
+							'		<div class="media-content">'+
+							'			<div class="appmsgSendedItem">'+
+							'				<a class="title-wrp" href="javascript:;">'+
+							'					<span class="icon cover" style="background-image:url('+material.items[0].thumb_url+');"></span>'+
+							'					<span class="title">[图文消息]'+material.items[0].title+'<span class="color-red">(多条图文只显示一条)</span></span>'+
+							'				</a>'+
+							'				<p class="desc"><a href="javascript:;" class="appmsg-desc">'+material.items[0].digest+'</a></p>'+
+							'			</div>'+
+							'		</div>'+
+							'	</div>'+
+							'	<div class="opr">'+
+							// '		<a href="./index.php?c=platform&a=material-post&type=reply&newsid='+material.id+'" target="_blank" class="del-gray">编辑</a>'+
+							'		<a href="javascript:;" data-media="'+material.media_id+'" class="del-gray" onclick="delmedia(\''+type+'\', this)">删除</a>'+
+							'	</div>'+
+							'</div>'+
+							'</li>'
+						);
+						break;
+					case 'voice':
+						replyVal.push(angular.toJson(material.media_id));
+						$('.keywords-list').append(
+							'<li>'+
+							'<div class="del-'+type+'-media">'+
+							'	<div class="desc">'+
+							'		<div class="media-content">'+
+							'			<div class="audio-msg">'+
+							'				<div class="icon-audio-wrp">'+
+							'					<span class="icon-audio-msg"></span>'+
+							'				</div>'+
+							'				<div class="audio-content">'+
+							'					<div class="audio-title">[语音]'+material.filename+'</div>'+
+							'				</div>'+
+							'			</div>'+
+							'		</div>'+
+							'	</div>'+
+							'	<div class="opr">'+
+							'		<a href="javascript:;" data-media="'+material.media_id+'" class="del-gray" onclick="delmedia(\''+type+'\', this)">删除</a>'+
+							'	</div>'+
+							'</div>'+
+							'</li>'
+						);
+						break;
+					case 'video':
+						replyVal.push(angular.toJson({
+							mediaid: material.media_id,
+							title: material.tag.title,
+							description: material.tag.description
+						}));
+
+						$('.keywords-list').append(
+							'<li>'+
+							'<div class="del-'+type+'-media">'+
+							'	<div class="desc">'+
+							'		<div class="media-content">'+
+							'			<div class="appmsgSendedItem">'+
+							'				<a class="title-wrp" href="javascript:;">'+
+							'					 <span class="icon cover" data-contenturl="'+material.tag.down_url+'"></span>'+
+							'					<span class="title">[视频]'+material.filename+'</span>'+
+							'				<p class="desc"><a href="javascript:;" class="appmsg-desc">'+(material.tag.description ? material.tag.description : '--')+'</a></p>'+
+							'				</a>'+
+							'			</div>'+
+							'		</div>'+
+							'	</div>'+
+							'	<div class="opr">'+
+							'		<a href="javascript:;" data-media="'+material.media_id+'" class="del-gray" onclick="delmedia(\''+type+'\', this)">删除</a>'+
+							'	</div>'+
+							'</div>'+
+							'</li>'
+						);
+						break;
+					case 'music':
+						replyVal.push(angular.toJson({
+							title: material.title,
+							url: material.url,
+							hqurl: material.HQUrl,
+							description: material.description,
+						}));
+						$('.keywords-list').append(
+							'<li>'+
+							'<div class="del-'+type+'-media">'+
+							'	<div class="desc">'+
+							'		<div class="media-content">'+
+							'			<div class="appmsgSendedItem">'+
+							'				<a class="title-wrp" href="javascript:;">'+
+							'					 <span class="icon cover" style="background-image:'+material.url+';"></span>'+
+							'					<span class="title">[音乐]'+material.title+'</span>'+
+							'				</a>'+
+							'				<p class="desc"><a href="javascript:;" class="appmsg-desc">'+material.description+'</a></p>'+
+							'			</div>'+
+							'		</div>'+
+							'	</div>'+
+							'	<div class="opr">'+
+							'		<a href="javascript:;" data-media="'+material.url+'" class="del-gray" onclick="delmedia(\''+type+'\', this)">删除</a>'+
+							'	</div>'+
+							'</div>'+
+							'</li>'
+						);
+						break;
+					case 'wxapp': 
+						if(material.media_id && !material.appid) {
+							setTimeout(function() {
+								window.select_mediaid(type, {image: material})
+							}, 300)
+						} else {
+							var length = JSON.parse('[' +$(':hidden[name="reply[reply_'+type+']"]').val() + ']' ).length
+							replyVal.push(angular.toJson(material));
+							$('.keywords-list').append(
+								'<li>'+
+								'<div class="del-'+type+'-media">'+
+								'	<div class="desc">'+
+								'		<div class="media-content">'+
+								'			<div class="appmsgSendedItem">'+
+								'				<a class="title-wrp" href="javascript:;">'+
+								'					 <span class="icon cover" style="background-image:url('+material.mediaUrl+');"></span>'+
+								'					<span class="title">[小程序]'+material.title+'</span>'+
+								'				<p class="desc"><a href="javascript:;" class="appmsg-desc"></a></p>'+
+								'				</a>'+
+								'			</div>'+
+								'		</div>'+
+								'	</div>'+
+								'	<div class="opr">'+
+								'		<a href="javascript:;" data-media="'+(length)+'" class="del-gray" onclick="delmedia(\''+type+'\', this)">删除</a>'+
+								'	</div>'+
+								'</div>'+
+								'</li>'
+							);
+						}
+						break;
+				}
+				$(':hidden[name="reply[reply_'+type+']"]').val(replyVal);
+			}
+			//显示隐藏-start
+			if((action == 'qr' || action == 'mass' || m == 'special' || m == 'welcome' || m == 'default') && replyVal.length > 0) {
+				$('.we7-select-msg').addClass('hide');
+			}
+			//显示隐藏-end
+		}, option);
+	};
+
+	window.initReplyController = function($scope) {
+		$scope.context = {};
+		$scope.context.items = {php echo json_encode($replies)};
+		var newsMediaIds = [];
+		var module_name = [];
+		var keyword_rids = [];
+		angular.forEach($scope.context.items, function(val, key){
+			var replyVal = [];
+			var type = key;
+			switch(type) {
+				case 'basic':
+					angular.forEach(val, function(basicVal, basicKey) {
+						replyVal.push(angular.toJson(basicVal.content));
+						$('.keywords-list').append(
+							'<li>'+
+							'<div class="del-'+type+'-media">'+
+							'	<div class="desc">'+
+							'		<div class="media-content">'+
+							'			<span data-toggle="tooltip" data-placement="bottom"  title="'+htmlEncode(basicVal.content)+'">'+htmlEncode(cutStr(basicVal.content,60))+'</span>'+
+							'		</div>'+
+							'	</div>'+
+							'	<div class="opr">'+
+							'		<a href="javascript:;" data-media="'+htmlEncode(angular.toJson(basicVal.content))+'" class="edit-gray" onclick="select_mediaid(\'basic\', '+htmlEncode(angular.toJson(basicVal.content))+')">编辑</a>'+
+							'		<a href="javascript:;" data-media="'+htmlEncode(angular.toJson(basicVal.content))+'" class="del-gray" onclick="delmedia(\''+type+'\', this)">删除</a>'+
+							'	</div>'+
+							'</div>'+
+							'</li>'
+						);
+					});
+					$(':hidden[name="reply[reply_'+type+']"]').val(replyVal);
+					break;
+				case 'news':
+					angular.forEach(val, function(newsVal, newsKey) {
+						var index = _.indexOf(newsMediaIds, newsVal.media_id);
+						replyVal.push(angular.toJson({
+							title: newsVal.title,
+							author: newsVal.author,
+							description: newsVal.description ? newsVal.description : newsVal.digest,
+							thumb: newsVal.thumb ? newsVal.thumb : newsVal.thumb_url,
+							url: newsVal.url,
+							createtime: newsVal.createtime,
+							displayorder: newsVal.displayorder ? newsVal.displayorder : 0,
+							incontent: newsVal.incontent ? newsVal.incontent : 0,
+							parent_id: newsVal.parent_id ? newsVal.parent_id : 0,
+							mediaid: newsVal.media_id,
+							attach_id: newsVal.attach_id,
+							model: newsVal.model
+						}));
+						if (index == -1) {
+							$('.keywords-list').append(
+								'<li>'+
+								'<div class="del-'+type+'-media">'+
+								'	<div class="desc">'+
+								'		<div class="media-content">'+
+								'			<div class="appmsgSendedItem">'+
+								'				<a class="title-wrp" href="javascript:;">'+
+								'					<span class="icon cover" style="background-image:url('+(newsVal.thumb ? newsVal.thumb : newsVal.thumb_url)+');"></span>'+
+								'					<span class="title">[图文消息]'+newsVal.title+(!newsVal.attach_id ? '<span class="color-red">(素材不存在或已被删除)</span>' : '')+
+								'					</span>'+
+								'				</a>'+
+								'				<p class="desc"><a href="javascript:;" class="appmsg-desc">'+(newsVal.description ? newsVal.description : '')+'</a></p>'+
+								'			</div>'+
+								'		</div>'+
+								'	</div>'+
+								'	<div class="opr">'+
+										// '<a href="./index.php?c=platform&a=material-post&type=reply&newsid='+(newsVal.attach_id ? newsVal.attach_id : '')+'&reply_news_id='+newsVal.id+'" target="_blank" class="del-gray">编辑</a>'  +
+								'		<a href="javascript:;" data-media="'+newsVal.media_id+'" class="del-gray" onclick="delmedia(\''+type+'\', this)">删除</a>'+
+								'	</div>'+
+								'</div>'+
+								'</li>'
+							);
+							newsMediaIds.push(newsVal.media_id);
+						}
+					});
+					$(':hidden[name="reply[reply_'+type+']"]').val(replyVal);
+					break;
+				case 'image':
+					angular.forEach(val, function(imageVal, imageKey) {
+						replyVal.push(angular.toJson(imageVal.mediaid));
+						$('.keywords-list').append(
+							'<li>'+
+							'<div class="del-'+type+'-media">'+
+							'	<div class="desc">'+
+							'		<div class="media-content">'+
+							'			<div class="appmsgSendedItem">'+
+							'				<a class="title-wrp" href="javascript:;">'+
+							'					 <span class="icon cover" style="background-image:url('+imageVal.img_url+');"></span>'+
+							'					<span class="title">[图片]</span>'+
+							'				</a>'+
+							'			</div>'+
+							'		</div>'+
+							'	</div>'+
+							'	<div class="opr">'+
+							'		<a href="javascript:;" data-media="'+imageVal.mediaid+'" class="del-gray" onclick="delmedia(\''+type+'\', this)">删除</a>'+
+							'	</div>'+
+							'</div>'+
+							'</li>'
+						);
+					});
+					$(':hidden[name="reply[reply_'+type+']"]').val(replyVal);
+					break;
+				case 'voice':
+					angular.forEach(val, function(voiceVal, voiceKey) {
+						replyVal.push(angular.toJson(voiceVal.mediaid));
+						$('.keywords-list').append(
+							'<li>'+
+							'<div class="del-'+type+'-media">'+
+							'	<div class="desc">'+
+							'		<div class="media-content">'+
+							'			<div class="audio-msg">'+
+							'				<div class="icon-audio-wrp">'+
+							'					<span class="icon-audio-msg"></span>'+
+							'				</div>'+
+							'				<div class="audio-content">'+
+							'					<div class="audio-title">[语音]'+voiceVal.title+'</div>'+
+							'				</div>'+
+							'			</div>'+
+							'		</div>'+
+							'	</div>'+
+							'	<div class="opr">'+
+							'		<a href="javascript:;" data-media="'+voiceVal.mediaid+'" class="del-gray" onclick="delmedia(\''+type+'\', this)">删除</a>'+
+							'	</div>'+
+							'</div>'+
+							'</li>'
+						);
+					});
+					$(':hidden[name="reply[reply_'+type+']"]').val(replyVal);
+					break;	
+				case 'video':
+					angular.forEach(val, function(videoVal, videoKey) {
+						replyVal.push(angular.toJson({
+							mediaid: videoVal.mediaid,
+							title: videoVal.title,
+							description: videoVal.description
+						}));
+						$('.keywords-list').append(
+							'<li>'+
+							'<div class="del-'+type+'-media">'+
+							'	<div class="desc">'+
+							'		<div class="media-content">'+
+							'			<div class="appmsgSendedItem">'+
+							'				<a class="title-wrp" href="javascript:;">'+
+							'					 <span class="icon cover" data-contenturl="'+videoVal.down_url+'"></span>'+
+							'					<span class="title">[视频]'+(videoVal.filename ? videoVal.filename : '--')+'</span>'+
+							'				<p class="desc"><a href="javascript:;" class="appmsg-desc">'+(videoVal.description ? videoVal.description : '--')+'</a></p>'+
+							'				</a>'+
+							'			</div>'+
+							'		</div>'+
+							'	</div>'+
+							'	<div class="opr">'+
+							'		<a href="javascript:;" data-media="'+videoVal.mediaid+'" class="del-gray" onclick="delmedia(\''+type+'\', this)">删除</a>'+
+							'	</div>'+
+							'</div>'+
+							'</li>'
+						);
+					});
+					$(':hidden[name="reply[reply_'+type+']"]').val(replyVal);
+					break;
+				case 'wxapp': 
+					angular.forEach(val, function(material, videoKey) {
+						replyVal.push(angular.toJson(material));
+						$('.keywords-list').append(
+							'<li>'+
+							'<div class="del-'+type+'-media">'+
+							'	<div class="desc">'+
+							'		<div class="media-content">'+
+							'			<div class="appmsgSendedItem">'+
+							'				<a class="title-wrp" href="javascript:;">'+
+							'					 <span class="icon cover" style="background-image:url('+material.thumb_url+');"></span>'+
+							'					<span class="title">[小程序]'+material.title+'</span>'+
+							'				<p class="desc"><a href="javascript:;" class="appmsg-desc"></a></p>'+
+							'				</a>'+
+							'			</div>'+
+							'		</div>'+
+							'	</div>'+
+							'	<div class="opr">'+
+							'		<a href="javascript:;" data-media="'+videoKey+'" class="del-gray" onclick="delmedia(\''+type+'\', this)">删除</a>'+
+							'	</div>'+
+							'</div>'+
+							'</li>'
+						);
+					});
+					$(':hidden[name="reply[reply_'+type+']"]').val(replyVal);
+					break;
+				case 'keyword':
+					angular.forEach(val, function(keywordVal, keywordKey) {
+						replyVal.push(angular.toJson(keywordVal.id));
+						var keywords = '&nbsp;&nbsp;' + keywordVal.content;
+						$('.keywords-list').append(
+								'<li>'+
+								'<div class="del-'+type+'-media">'+
+								'	<div class="desc">'+
+								'		<div class="media-content">'+
+								'				<a class="title-wrp" href="javascript:;">'+
+								'					<span class="title">[关键字]'+keywordVal.name+'</span>'+
+								'				</a>'+
+								'				<p class="desc"><a href="javascript:;" class="appmsg-desc">'+keywords+'</a></p>'+
+								'		</div>'+
+								'	</div>'+
+								'	<div class="opr">'+
+								// '<a href="./index.php?c=platform&a=reply&do=post&m=keyword&rid=' + keywordVal.rid + '" target="_blank" class="del-gray">编辑</a> '  +
+								'<a href="javascript:;" data-media="'+keywordVal.name+'" class="del-gray" onclick="delmedia(\''+type+'\', this)">删除</a>'+
+								'	</div>'+
+								'</div>'+
+								'</li>'
+						);
+						keyword_rids.push(keywordVal.id);
+					});
+					$(':hidden[name="reply[reply_'+type+']"]').val(keyword_rids);
+					break;
+				case 'module':
+					angular.forEach(val, function(keywordVal, keywordKey) {
+						replyVal.push(angular.toJson(keywordVal.rid));
+						var keywords = '&nbsp;&nbsp;' + keywordVal.content;
+						$('.keywords-list').append(
+								'<li>'+
+								'<div class="del-'+type+'-media">'+
+								'	<div class="desc">'+
+								'		<div class="media-content">'+
+								'			<div class="appmsgSendedItem">'+
+								'				<a class="title-wrp" href="javascript:;">'+
+								'					 <span class="icon cover" style="background-image:url('+keywordVal.icon+');"></span>'+
+								'					<span class="title">[模块]'+keywordVal.title+'</span>'+
+								'				</a>'+
+								'			</div>'+
+								'		</div>'+
+								'	</div>'+
+								'	<div class="opr">'+
+								'		<a href="javascript:;" data-media="'+keywordVal.name+'" class="del-gray" onclick="delmedia(\''+type+'\', this)">删除</a>'+
+								'	</div>'+
+								'</div>'+
+								'</li>'
+						);
+						module_name.push(keywordVal.name);
+					});
+					$(':hidden[name="reply[reply_'+type+']"]').val(module_name);
+					break;
+				case 'music':
+					angular.forEach(val, function(musicVal, musicKey) {
+						replyVal.push(angular.toJson({
+							title: musicVal.title,
+							url: musicVal.url,
+							hqurl: musicVal.hqurl,
+							description: musicVal.description,
+						}));
+						$('.keywords-list').append(
+							'<li>'+
+							'<div class="del-'+type+'-media">'+
+							'	<div class="desc">'+
+							'		<div class="media-content">'+
+							'			<div class="appmsgSendedItem">'+
+							'				<a class="title-wrp" href="javascript:;">'+
+							'					 <span class="icon cover" style="background-image:'+musicVal.url+';"></span>'+
+							'					<span class="title">[音乐]'+musicVal.title+'</span>'+
+							'				</a>'+
+							'				<p class="desc"><a href="javascript:;" class="appmsg-desc">'+musicVal.description+'</a></p>'+
+							'			</div>'+
+							'		</div>'+
+							'	</div>'+
+							'	<div class="opr">'+
+							'		<a href="javascript:;" data-media="'+musicVal.url+'" class="del-gray" onclick="delmedia(\''+type+'\', this)">删除</a>'+
+							'	</div>'+
+							'</div>'+
+							'</li>'
+						);
+					});
+					$(':hidden[name="reply[reply_'+type+']"]').val(replyVal);
+					break;
+			}
+			//显示隐藏-start
+			if((action == 'qr' || action == 'mass' || m == 'special' || m == 'welcome' || m == 'default') && replyVal.length > 0) {
+				$('.we7-select-msg').addClass('hide');
+			}
+			//显示隐藏-end
+		});
+	};
+
+	function htmlEncode(str) {
+		var s = "";
+		if(str.length == 0) return "";
+		s = str.replace(/&/g,"&amp;");
+		s = s.replace(/</g,"&lt;");
+		s = s.replace(/>/g,"&gt;");
+		s = s.replace(/\'/g,"&#039;");
+		s = s.replace(/\"/g,"&quot;");
+		s = s.replace(/\n/g, "\\n");
+		return s;
+	}
+	function htmlDecode(str) {
+		var s = "";
+		if(str.length == 0) return "";
+		s = str.replace(/&amp;/g,"&");
+		s = s.replace(/&lt;/g,"<");
+		s = s.replace(/&gt;/g,">");
+		s = s.replace(/&#039;/g,"'");
+		s = s.replace(/&quot;/g,'"');
+		s = s.replace(/\\n/g,'\n');
+		return s;
+	}
+    function cutStr(str, len) {
+        var str_length = 0;
+        var str_len = 0;
+        str_cut = new String();
+        str_len = str.length;
+        for (var i = 0; i < str_len; i++) {
+            a = str.charAt(i);
+            str_length++;
+            if (escape(a).length > 4) {
+                //中文字符的长度经编码之后大于4  
+                str_length++;
+            }
+            str_cut = str_cut.concat(a);
+            if (str_length >= len) {
+                str_cut = str_cut.concat("...");
+                return str_cut;
+            }
+        }
+        //如果给定字符串小于指定长度,则返回源字符串;  
+        if (str_length < len) {
+            return str;
+        }
+    }
+	$(document).on("mouseover","body",function(){
+	 	$("[data-toggle='tooltip']").tooltip();
+	});
+</script>
+<style lang="scss">
+	.we7-select-msg ul li.tab-nav {
+			width: 160px !important;
+			padding: 10px 0 !important;
+	}
+</style>

+ 88 - 0
framework/builtin/core/template/mobile/detail.html

xqd
@@ -0,0 +1,88 @@
+{template 'header'}
+<div id="activity-detail">
+<style type="text/css">
+@charset "utf-8";
+html{background:#FFF;color:#000;}
+body, div, dl, dt, dd, h1, h2, h3, h4, h5, h6, pre, code, form, fieldset, legend, input, textarea, p, blockquote, th, td{margin:0;padding:0;}
+table{border-collapse:collapse;border-spacing:0;}
+fieldset, img{border:0;}
+address, caption, cite, code, dfn,  th, var{font-style:normal;font-weight:normal;}
+ol, ul{list-style:none;}
+caption, th{text-align:left;}
+h1, h2, h3, h4, h5, h6{font-size:100%;font-weight:normal;}
+q:before, q:after{content:'';}
+abbr, acronym{border:0;font-variant:normal;}
+sup{vertical-align:text-top;}
+sub{vertical-align:text-bottom;}
+input, textarea, select{font-family:inherit;font-size:inherit;font-weight:inherit;}
+input, textarea, select{font-size:100%;}
+legend{color:#000;}
+html{background-color:#f8f7f5;}
+body{background:#f8f7f5;color:#222;font-family:Helvetica, STHeiti STXihei, Microsoft JhengHei, Microsoft YaHei, Tohoma, Arial;height:100%;position:relative;}
+body > .tips{display:none;left:50%;padding:20px;position:fixed;text-align:center;top:50%;width:200px;z-index:100;}
+.page{padding:15px;}
+.page .page-error, .page .page-loading{line-height:30px;position:relative;text-align:center;}
+
+#activity-detail .page-bizinfo{border-bottom:2px solid #EEE;}
+#activity-detail .page-bizinfo .header{padding: 15px 15px 10px; border-bottom:1px solid #CCC;}
+#activity-detail .page-bizinfo .header #activity-name{color:#000;font-size:20px;font-weight:bold;word-break:normal;word-wrap:break-word;}
+#activity-detail .page-bizinfo .header #post-date{color:#8c8c8c;font-size:11px;margin:0;}
+#activity-detail .page-content{padding:15px;}
+#activity-detail .page-content .media{margin-bottom:18px;}
+#activity-detail .page-content .media img{width:100%;}
+#activity-detail .page-content .text{color:#3e3e3e;font-size:1.5;line-height:1.5;width: 100%;overflow: hidden;zoom:1;}
+#activity-detail .page-content .text p{min-height:1.5em;min-height: 1.5em;word-wrap: break-word;word-break:break-all;}
+#activity-list .header{font-size:20px;}
+#activity-list .page-list{border:1px solid #ccc;border-radius:5px;margin:18px 0;overflow:hidden;}
+#activity-list .page-list .line.btn{border-radius:0;margin:0;text-align:left;}
+#activity-list .page-list .line.btn .checkbox{height:25px;line-height:25px;padding-left:35px;position:relative;}
+#activity-list .page-list .line.btn .checkbox .icons{background-color:#ccc;left:0;position:absolute;top:0;}
+#activity-list .page-list .line.btn.off .icons{background-image:none;}
+#activity-list #save.btn{background-image:linear-gradient(#22dd22, #009900);background-image:-moz-linear-gradient(#22dd22, #009900);background-image:-ms-linear-gradient(#22dd22, #009900);background-image:-o-linear-gradient(#22dd22, #009900);background-image:-webkit-gradient(linear, left top, left bottom, from(#22dd22), to(#009900));background-image:-webkit-linear-gradient(#22dd22, #009900);}
+.vm{vertical-align:middle;}
+.tc{text-align:center;}
+.db{display:block;}
+.dib{display:inline-block;}
+.b{font-weight:700;}
+.clr{clear:both;}
+.text img{max-width:100%;}
+.page-url{padding-top:18px;}
+.page-url-link{color:#607FA6;font-size:14px;text-decoration:none;text-shadow:0 1px #ffffff;-webkit-text-shadow:0 1px #ffffff;-moz-text-shadow:0 1px #ffffff;}
+#footer{text-align:center; background-color:#DADADA; border-top:1px solid #B9B9B9;}
+#footer .copyright{border-top: 1px solid #CACACA;color: #7B7B7B;height: 35px;line-height: 35px;font-size: 12px;}
+#footer .copyright a{display: block;width: 100%;height: 100%;}
+#mbutton{padding:15px 10px 15px 10px; overflow:hidden; border-bottom:1px #DDD solid;}
+#mbutton > span{float:right; display:inline-block; background:#58a3ff; border:1px #63a0eb solid; color:#FFF; height:30px; line-height:30px; padding:0 10px; margin-left:10px;}
+#mcover{position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(0, 0, 0, 0.7);display:none;z-index:20000;}
+#mcover img{position:fixed;right: 18px;top:5px;width:260px;height:180px;z-index:20001;}
+</style>
+<div class="page-bizinfo">
+	<div class="header">
+		<h1 id="activity-name">{$row['title']}</h1>
+		<span id="post-date">
+			<span>{php echo date('Y-m-d', $row['createtime'])}</span>
+			<span>{$row['author']}</span>
+			<a href="{$subscribeurl}">
+				{if empty($_W['account']['name'])}
+					微擎团队
+				{else}
+					{$_W['account']['name']}
+				{/if}
+			</a>
+		</span>
+	</div>
+</div>
+
+<div class="page-content">
+	{if $row['incontent'] != 0}
+		<div class="media">
+			<img onerror="this.parentNode.removeChild(this)" src="{php echo tomedia($row['thumb']);}">
+		</div>
+	{/if}
+	<div class="text">
+		{$row['content']}
+	</div>
+</div>
+</div>
+{php $_share = array('content' => $row['description'], 'title' => $row['title'], 'imgUrl' => tomedia($row['thumb']));}
+{template 'footer'}

+ 91 - 0
framework/builtin/core/template/mobile/pay.html

xqd
@@ -0,0 +1,91 @@
+<header class="mui-bar mui-bar-nav">
+	<a class="mui-icon mui-icon-back mui-pull-left js-switch-modal" href="javascript:;"></a>
+	<a class="mui-icon mui-icon-close mui-pull-right js-switch-pay-close"></a>
+	<h1 class="mui-title">付款详情</h1>
+</header>
+<div class="mui-content">
+	<div id="pay-main-modal" class="js-main-modal">
+		<ul class="mui-table-view mui-table-view-chevron">
+			<li class="mui-table-view-cell">
+				<span class="mui-text-muted">支付宝账号</span>
+				<span class="mui-pull-right">188****1234</span>
+			</li>
+			<li class="mui-table-view-cell js-switch-pay">
+				<a class="mui-navigate-right mui-media">
+					<span class="mui-text-muted">付款方式</span>
+					<span class="mui-pull-right js-pay-default-method"></span>
+				</a>
+			</li>
+		</ul>
+		<div class="mui-row mui-pa15">
+			<div class="mui-col-xs-6">需付款</div>
+			<div class="mui-col-xs-6 mui-text-right mui-big"><span class="js-pay-fee"></span>元</div>
+		</div>
+		<div class="mui-content-padded">
+			<form action="{php echo url('mc/cash/');}" method="post">
+				<input type="hidden" name="params" value="{php echo base64_encode(json_encode($params));}" />
+				<input type="hidden" name="code" value="" />
+				<input type="hidden" name="coupon_id" value="" />
+				<input type="hidden" name="do" value="wechat" />
+				<button type="submit" class="mui-btn mui-btn-success mui-btn-block" data-payparams="{php echo base64_encode(json_encode($params));}" value="确认支付">确认支付</button>
+			</form>
+		</div>
+	</div>
+	<ul id="pay-method-modal" class="mui-table-view mui-table-view-chevron js-switch-pay-modal" style="display:none;">
+		{if !empty($pay['credit']['switch'])}
+		<li class="mui-table-view-cell" data-method="credit" data-title="余额">
+			<a class="mui-navigate-right mui-media" href="javascript:;">
+				<img src="./resource/images/money.png" alt="" class="mui-media-object mui-pull-left"/>
+				<span class="mui-media-body mui-block">
+					余额
+					<span class="mui-block mui-text-muted mui-rmb mui-mt5">{php echo sprintf('%.2f', $credtis[$setting['creditbehaviors']['currency']]);}</span>
+				</span>
+			</a>
+		</li>
+		{/if}
+		{if $pay['baifubao']['switch']}
+		<li class="mui-table-view-cell" data-method="baifubao" data-title="百度钱包">
+			<a class="mui-navigate-right mui-media" href="javascript:;">
+				<img src="./resource/images/baidu-pay.png" alt="" class="mui-media-object mui-pull-left"/>
+				<span class="mui-media-body mui-block">
+					百度钱包
+					<span class="mui-block mui-text-muted mui-mt5">百度安全支付服务</span>
+				</span>
+			</a>
+		</li>
+		{/if}
+		{if $pay['unionpay']['switch']}
+		<li class="mui-table-view-cell" data-method="unionpay" data-title="银联支付">
+			<a class="mui-navigate-right mui-media" href="javascript:;">
+				<img src="./resource/images/yl-icon.png" alt="" class="mui-media-object mui-pull-left"/>
+				<span class="mui-media-body mui-block">
+					银联支付
+					<span class="mui-block mui-text-muted mui-mt5">银联安全支付服务</span>
+				</span>
+			</a>
+		</li>
+		{/if}
+		{if !empty($pay['wechat']['switch'])}
+		<li class="mui-table-view-cell" data-method="wechat" data-title="微信支付">
+			<a class="mui-navigate-right mui-media" href="javascript:;">
+				<img src="./resource/images/wx-icon.png" alt="" class="mui-media-object mui-pull-left"/>
+				<span class="mui-media-body mui-block">
+					微信支付
+					<span class="mui-block mui-text-muted mui-mt5">微信支付,安全快捷</span>
+				</span>
+			</a>
+		</li>
+		{/if}
+		{if !empty($pay['alipay']['switch'])}
+		<li class="mui-table-view-cell" data-method="alipay" data-title="支付宝">
+			<a class="mui-navigate-right mui-media" href="javascript:;">
+				<img src="./resource/images/zfb-icon.png" alt="" class="mui-media-object mui-pull-left"/>
+				<span class="mui-media-body mui-block">
+					支付宝
+					<span class="mui-block mui-text-muted mui-mt5">简单、安全、快速</span>
+				</span>
+			</a>
+		</li>
+		{/if}
+	</ul>
+</div>

+ 60 - 0
framework/builtin/core/wxapp.php

xqd
@@ -0,0 +1,60 @@
+<?php
+
+class CoreModuleWxapp extends WeModuleWxapp {
+	public function doPagePay() {
+		global $_W, $_GPC;
+		$order_info = table('core_paylog')
+			->searchWithUniacid($_W['uniacid'])
+			->searchWithModule(safe_gpc_string($_GPC['module_name']))
+			->searchWithTid(safe_gpc_string($_GPC['orderid']))
+			->get();
+		$order = array(
+			'tid' => $order_info['tid'],
+			'user' => $_SESSION['openid'],
+			'fee' => $order_info['fee'],
+			'title' => safe_gpc_string($_GPC['title']),
+		);
+
+		$this->module = array('name' => $order_info['module']);
+		$paydata = $this->pay($order);
+		$this->result(0, '', $paydata);
+	}
+
+	
+	public function doPagePayResult() {
+		global $_GPC, $_W;
+		$log = table('core_paylog')
+			->searchWithUniacid($_W['uniacid'])
+			->searchWithModule(safe_gpc_string($_GPC['module_name']))
+			->searchWithTid(safe_gpc_string($_GPC['orderid']))
+			->get();
+		if (!empty($log) && !empty($log['status'])) {
+			if (!empty($log['tag'])) {
+				$tag = iunserializer($log['tag']);
+				$log['uid'] = $tag['uid'];
+			}
+			$site = WeUtility::createModuleSite($log['module']);
+			if (!is_error($site)) {
+				$method = 'payResult';
+				if (method_exists($site, $method)) {
+					$ret = array();
+					$ret['weid'] = $log['uniacid'];
+					$ret['uniacid'] = $log['uniacid'];
+					$ret['result'] = 'success';
+					$ret['type'] = $log['type'];
+					$ret['from'] = 'return';
+					$ret['tid'] = $log['tid'];
+					$ret['uniontid'] = $log['uniontid'];
+					$ret['user'] = $log['openid'];
+					$ret['fee'] = $log['fee'];
+					$ret['tag'] = $tag;
+					$ret['is_usecard'] = $log['is_usecard'];
+					$ret['card_type'] = $log['card_type'];
+					$ret['card_fee'] = $log['card_fee'];
+					$ret['card_id'] = $log['card_id'];
+					exit($site->$method($ret));
+				}
+			}
+		}
+	}
+}

+ 43 - 0
framework/builtin/cover/processor.php

xqd
@@ -0,0 +1,43 @@
+<?php
+/**
+ * [WeEngine System] Copyright (c) 2014 WE7.CC
+ * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
+ */
+defined('IN_IA') or exit('Access Denied');
+
+class CoverModuleProcessor extends WeModuleProcessor {
+	public function respond() {
+		global $_W;
+		$content = $this->message['content'];
+		$reply = table('cover_reply')->where(array('rid' => $this->rule))->get();
+		if (!empty($reply)) {
+			load()->model('module');
+			$module = module_fetch($reply['module']);
+			if (empty($module) && !in_array($reply['module'], array('site', 'mc', 'card', 'page', 'clerk'))) {
+				return '';
+			}
+			$url = $reply['url'];
+			if (empty($reply['url'])) {
+				$entry = table('modules_bindings')
+					->select('eid')
+					->where(array(
+						'module' => $reply['module'],
+						'do' => $reply['do']
+					))
+					->get();
+				$url = url('entry', array('eid' => $entry['eid']));
+			}
+			$news = array();
+			$news[] = array(
+				'title' => $reply['title'],
+				'description' => $reply['description'],
+				'picurl' => $reply['thumb'],
+				'url' => $url,
+			);
+
+			return $this->respNews($news);
+		}
+
+		return '';
+	}
+}

BIN
framework/builtin/custom/icon.jpg


+ 1 - 0
framework/builtin/custom/index.html

xqd
@@ -0,0 +1 @@
+ 

BIN
framework/builtin/custom/preview.jpg


+ 37 - 0
framework/builtin/custom/processor.php

xqd
@@ -0,0 +1,37 @@
+<?php
+/**
+ * [WeEngine System] Copyright (c) 2014 WE7.CC
+ * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
+ */
+defined('IN_IA') or exit('Access Denied');
+
+class CustomModuleProcessor extends WeModuleProcessor {
+	
+	public function respond() {
+		
+		if($this->rule == -1) {
+			return $this->respCustom();
+		}
+		$reply = table('custom_reply')->where(array('rid IN' => $this->rule))->orderby('RAND()')->get();
+		$nhour = date('H', TIMESTAMP);
+		$flag = 0;
+		if($reply['start1'] == 0 && $reply['end'] == 24) {
+			$flag = 1;
+		} elseif($reply['start1'] != '-1' && ($nhour >= $reply['start1']) && ($nhour < $reply['end1'])) {
+			$flag = 1;
+		} elseif($reply['start2'] != '-1' &&  ($nhour >= $reply['start2']) && ($nhour < $reply['end2'])) {
+			$flag = 1;
+		}
+
+		if($flag == 1) {
+			return $this->respCustom();
+		} else {
+			$content = '多客服接入时间为:' . intval($reply['start1']) .'时~' . $reply['end1'] . '时';
+			if($reply['start2'] != '-1') {
+				$content .= ',' . $reply['start2'] . '时~' . $reply['end2'] . '时';
+			}
+			$reply['content'] = $content;
+			return $this->respText($reply['content']);
+		}
+	}
+}

+ 82 - 0
framework/builtin/custom/site.php

xqd
@@ -0,0 +1,82 @@
+<?php
+/**
+ * [WeEngine System] Copyright (c) 2014 WE7.CC
+ * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
+ */
+defined('IN_IA') or exit('Access Denied');
+
+class CustomModuleSite extends WeModuleSite {
+	public function getTabUrls() {
+		$urls = array();
+		$urls[] = array('title' => '客服聊天记录', 'url' => $this->createWebUrl('chatlog'), 'do' => 'chatlog');
+
+		return $urls;
+	}
+
+	public function doWebChatlog() {
+		global $_GPC, $_W;
+		load()->func('tpl');
+		$starttime = empty($_GPC['starttime']) ? strtotime(date('Y-m-d')) : strtotime($_GPC['starttime']);
+		if (!empty($_GPC['token'])) {
+			unset($_GPC['token']);
+			$avatar = '';
+			$endtime = $starttime + 23 * 3600 + 3599;
+			$acid = $_W['acid'];
+			if (!empty($_GPC['nickname']) && empty($_GPC['openid'])) {
+				$user = table('mc_members')
+					->select(array('b.openid', 'a.avatar', 'b.nickname'))
+					->searchWithMappingFans()
+					->where(array(
+						'b.acid' => $_W['acid'],
+						'a.nickname' => safe_gpc_string($_GPC['nickname'])
+					))
+					->get();
+				if (empty($user['openid'])) {
+					itoast('没有找到昵称为 "' . $_GPC['nickname'] . '" 的用户', $this->createWebUrl('chatlog', array('acid' => $acid, 'nickname' => $_GPC['nickname'], 'openid' => $_GPC['openid'], 'starttime' => $_GPC['starttime'])), 'error');
+				} else {
+					if (!empty($user['avatar'])) {
+						$avatar = tomedia($user['avatar']);
+						$nickname = $user['nickname'];
+					}
+				}
+			} else {
+				$openid = safe_gpc_string($_GPC['openid']);
+				$user = table('mc_members')
+					->select(array('b.openid', 'a.avatar', 'b.nickname'))
+					->searchWithMappingFans()
+					->where(array(
+						'b.uniacid' => $_W['uniacid'],
+						'b.openid' => $openid
+					))
+					->get();
+				if (!empty($user['avatar'])) {
+					$avatar = tomedia($user['avatar']);
+					$nickname = $user['nickname'];
+				}
+			}
+			if (empty($user['openid'])) {
+				itoast('请输入粉丝昵称或者粉丝openid', referer(), 'error');
+			}
+			if ($acid > 0 && !empty($starttime) && !empty($endtime)) {
+				$pindex = max(1, intval($_GPC['page']));
+				$acc = WeAccount::createByUniacid();
+				$params = array('openid' => trim($user['openid']), 'starttime' => $starttime, 'endtime' => $endtime, 'pageindex' => $pindex, 'pagesize' => 50);
+				$logs = $acc->fetchChatLog($params);
+				$next = 1;
+				if (is_error($logs) || empty($logs['recordlist']) || (count($logs['recordlist']) < $params['pagesize'])) {
+					$next = 0;
+				}
+				$codedata = array();
+				$codedata[1000] = '创建未接入会话';
+				$codedata[1001] = '接入会话';
+				$codedata[1002] = '主动发起会话';
+				$codedata[1004] = '关闭会话';
+				$codedata[1005] = '抢接会话';
+				$codedata[2001] = '公众号收到消息';
+				$codedata[2002] = '客服发送消息';
+				$codedata[2003] = '客服收到消息';
+			}
+		}
+		include $this->template('chatlog');
+	}
+}

+ 172 - 0
framework/builtin/custom/template/chatlog.html

xqd
@@ -0,0 +1,172 @@
+{template 'common/header'}
+<div class="panel panel-info">
+	<div class="panel-heading">筛选</div>
+	<div class="panel-body">
+		<form action="./index.php" method="get" class="form-horizontal" role="form" id="form1">
+			<input type="hidden" name="c" value="site">
+			<input type="hidden" name="a" value="entry">
+			<input type="hidden" name="m" value="custom">
+			<input type="hidden" name="do" value="chatlog">
+			<input type="hidden" name="token" value="{$_W['token']}">
+			<input type="hidden" name="page" value="1" id="page">
+			<div class="form-group">
+				<label class="col-xs-12 col-sm-3 col-md-2 control-label">粉丝昵称</label>
+				<div class="col-sm-6 col-md-8 col-lg-8">
+					<input type="text" class="form-control" name="nickname" id="nickname" placeholder="请输入粉丝昵称" value="{$_GPC['nickname']}" />
+				</div>
+			</div>
+			<div class="form-group">
+				<label class="col-xs-12 col-sm-3 col-md-2 control-label">粉丝openid</label>
+				<div class="col-sm-6 col-md-8 col-lg-8">
+					<input type="text" class="form-control" name="openid" id="openid" placeholder="请输入粉丝openid" value="{$_GPC['openid']}" />
+				</div>
+			</div>
+			<div class="form-group">
+				<label class="col-xs-12 col-sm-3 col-md-2 control-label">时间</label>
+				<div class="col-sm-6 col-md-8 col-lg-8">
+					{php echo tpl_form_field_date('starttime', $starttime, false)}
+					<div class="help-block">公众平台不支持跨日查询</div>
+				</div>
+				<div class="pull-right col-xs-12 col-sm-3 col-md-2 col-lg-2">
+					<button class="btn btn-default" id="search"><i class="fa fa-search"></i> 搜索</button>
+				</div>
+			</div>
+		</form>
+	</div>
+</div>
+<style>
+	.infol{margin-left:35px;padding:5px;max-width:60%;}
+	.infor{margin-right:35px;padding:5px;max-width:60%;}
+	.pull-left,.pull-right{position:relative;}
+	.spanabsolute{position:absolute;top:50px;left:0;}
+	.spanrabsolute{position:absolute;top:50px;right:10px;}
+</style>
+<div class="panel panel-default" style="margin-bottom:0">
+	<div class="panel-heading">聊天记录</div>
+	<div class="panel-body">
+		{if is_error($logs)}
+			<div class="text-center text-danger"><i class="fa fa-info-circle"></i> 搜索消息记录时出错,错误详情:{$logs['message']}</div>
+		{elseif empty($logs['recordlist'])}
+			<div class="text-center"><i class="fa fa-info-circle"> 没有符合条件的记录</i></div>
+		{else}
+			{loop $logs['recordlist'] $log}
+				{if $log['opercode'] == 1000}
+					<div class="pull-left col-lg-12 col-md-12 col-sm-12 col-xs-12">
+						<div class="pull-left">
+							<img src="{if !empty($avatar)}{$avatar}{else}resource/images/noavatar_middle.gif{/if}" width="48"><br>
+							<span class="spanabsolute">{if !empty($nickname)}{$nickname}{else}{$log['openid']}{/if}</span>
+						</div>
+						<div class="alert alert-info pull-left infol">
+							{$codedata[$log['opercode']]}<br>
+							<small class="text-danger">{php echo date('m-d H:i:s', $log['time']);} --- {$codedata[$log['opercode']]}</small>
+						</div>
+						<div style="clear:both"></div>
+					</div>
+				{elseif $log['opercode'] == 1001}
+				<div class="pull-left col-lg-12 col-md-12 col-sm-12 col-xs-12">
+					<div class="pull-right">
+						<img src="resource/images/noavatar_middle.gif" width="48"><br>
+						<span class="spanrabsolute">{$log['worker']}</span>
+					</div>
+					<div class="alert alert-danger pull-right infor">
+						{$codedata[$log['opercode']]} <br>
+						<small class="text-danger">{php echo date('m-d H:i:s', $log['time']);} --- {$codedata[$log['opercode']]}</small>
+					</div>
+				</div>
+				{elseif $log['opercode'] == 1002}
+				<div class="pull-left col-lg-12 col-md-12 col-sm-12 col-xs-12">
+					<div class="pull-right">
+						<img src="resource/images/noavatar_middle.gif" width="48"><br>
+						<span class="spanrabsolute">{$log['worker']}</span>
+					</div>
+					<div class="alert alert-danger pull-right infor">
+						{$log['text']}<br>
+						<small class="text-danger">{php echo date('m-d H:i:s', $log['time']);} --- {$codedata[$log['opercode']]}</small>
+					</div>
+				</div>
+				{elseif $log['opercode'] == 1004}
+				<div class="pull-left col-lg-12 col-md-12 col-sm-12 col-xs-12">
+					<div class="pull-right">
+						<img src="resource/images/noavatar_middle.gif" width="48"><br>
+						<span class="spanrabsolute">{$log['worker']}</span>
+					</div>
+					<div class="alert alert-danger pull-right infor">
+						{$codedata[$log['opercode']]}<br>
+						<small class="text-danger">{php echo date('m-d H:i:s', $log['time']);} --- {$codedata[$log['opercode']]}</small>
+					</div>
+				</div>
+				{elseif $log['opercode'] == 1005}
+				<div class="pull-left col-lg-12 col-md-12 col-sm-12 col-xs-12">
+					<div class="pull-right">
+						<img src="resource/images/noavatar_middle.gif" width="48"><br>
+						<span class="spanrabsolute">{$log['worker']}</span>
+					</div>
+					<div class="alert alert-danger pull-right infor">
+						{$codedata[$log['opercode']]}<br>
+						<small class="text-danger">{php echo date('m-d H:i:s', $log['time']);} --- {$codedata[$log['opercode']]}</small>
+					</div>
+				</div>
+				{elseif $log['opercode'] == 2001}
+				<div class="pull-left col-lg-12 col-md-12 col-sm-12 col-xs-12">
+					<div class="pull-left">
+						<img src="{if !empty($avatar)}{$avatar}{else}resource/images/noavatar_middle.gif{/if}" width="48"><br>
+						<span class="spanabsolute">{if !empty($nickname)}{$nickname}{else}{$log['openid']}{/if}</span>
+					</div>
+					<div class="alert alert-info pull-left infol">
+						{$log['text']}<br>
+						<small class="text-danger">{php echo date('m-d H:i:s', $log['time']);} --- {$codedata[$log['opercode']]}</small>
+					</div>
+				</div>
+				{elseif $log['opercode'] == 2002}
+				<div class="pull-left col-lg-12 col-md-12 col-sm-12 col-xs-12">
+					<div class="pull-right">
+						<img src="resource/images/noavatar_middle.gif" width="48"><br>
+						<span class="spanrabsolute">{$log['worker']}</span>
+					</div>
+					<div class="alert alert-danger pull-right infor">
+						{$log['text']}<br>
+						<small class="text-danger">{php echo date('m-d H:i:s', $log['time']);} --- {$codedata[$log['opercode']]}</small>
+					</div>
+				</div>
+				{elseif $log['opercode'] == 2003}
+				<div class="pull-left col-lg-12 col-md-12 col-sm-12 col-xs-12">
+					<div class="pull-left">
+						<img src="{if !empty($avatar)}{$avatar}{else}resource/images/noavatar_middle.gif{/if}" width="48"><br>
+						<span class="spanabsolute">{if !empty($nickname)}{$nickname}{else}{$log['openid']}{/if}</span>
+					</div>
+					<div class="alert alert-info pull-left infol">
+						{$log['text']}<br>
+						<small class="text-danger">{php echo date('m-d H:i:s', $log['time']);} --- {$codedata[$log['opercode']]}</small>
+					</div>
+				</div>
+				{/if}
+			{/loop}
+		{/if}
+	</div>
+</div>
+<form class="form-horizontal" role="form" style="margin-top:10px">
+	<div class="form-group">
+		<div class="col-sm-12">
+			{if $pindex > 1}
+				<a href="javascript:;" onclick="$('#page').val($(this).attr('page'));$('#form1').submit();return;" id="prev" page="{php echo ($pindex - 1)}"  class="btn btn-default"><i class="fa fa-angle-double-left"></i></a>
+			{/if}
+			{if !empty($next)}
+				<a href="javascript:;" onclick="$('#page').val($(this).attr('page'));$('#form1').submit();return;" id="next" page="{php echo ($pindex + 1)}"class="btn btn-primary"><i class="fa fa-angle-double-right"></i></a>
+			{/if}
+		</div>
+	</div>
+</form>
+<script>
+	require(['util'], function(u) {
+		$('#form1').submit(function(){
+			var nickname = $('#nickname').val().trim();
+			var openid = $('#openid').val().trim();
+			var starttime = $('input[name="starttime"]').val();
+			if(nickname == '' && openid == '') {
+				u.message('粉丝openid和粉丝昵称必须填写一项');
+				return false;
+			}
+		});
+	});
+</script>
+{template 'common/footer'}

+ 32 - 0
framework/builtin/default/processor.php

xqd
@@ -0,0 +1,32 @@
+<?php
+/**
+ * [WeEngine System] Copyright (c) 2014 WE7.CC
+ * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
+ */
+defined('IN_IA') or exit('Access Denied');
+
+class DefaultModuleProcessor extends WeModuleProcessor {
+	public function respond() {
+		global $_W, $engine;
+		if ('trace' == $this->message['type']
+			|| 'view_miniprogram' == $this->message['event']
+			|| 'VIEW' == $this->message['event']
+		) {
+			return $this->respText('');
+		}
+		$setting = uni_setting($_W['uniacid'], array('default'));
+		if (!empty($setting['default'])) {
+			$flag = array('image' => 'url', 'link' => 'url', 'text' => 'content');
+			$message = $this->message;
+			$message['type'] = 'text';
+			$message['content'] = $setting['default'];
+			$message['redirection'] = true;
+			$message['source'] = 'default';
+			$message['original'] = $this->message[$flag[$this->message['type']]];
+			$pars = $engine->analyzeText($message);
+			if (is_array($pars)) {
+				return array('params' => $pars);
+			}
+		}
+	}
+}

BIN
framework/builtin/images/icon.jpg


BIN
framework/builtin/images/preview.jpg


+ 18 - 0
framework/builtin/images/processor.php

xqd
@@ -0,0 +1,18 @@
+<?php
+/**
+ * [WeEngine System] Copyright (c) 2014 WE7.CC
+ * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
+ */
+defined('IN_IA') or exit('Access Denied');
+
+class ImagesModuleProcessor extends WeModuleProcessor {
+	public function respond() {
+		global $_W;
+		$rid = $this->rule;
+		$mediaid = table('images_reply')->where(array('rid' => $rid))->getcolumn('mediaid');
+		if (empty($mediaid)) {
+			return false;
+		}
+		return $this->respImage($mediaid);
+	}
+}

+ 1 - 0
framework/builtin/model.php

xqd
@@ -0,0 +1 @@
+ 

BIN
framework/builtin/music/icon.jpg


BIN
framework/builtin/music/preview.jpg


+ 23 - 0
framework/builtin/music/processor.php

xqd
@@ -0,0 +1,23 @@
+<?php
+/**
+ * [WeEngine System] Copyright (c) 2014 WE7.CC
+ * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
+ */
+defined('IN_IA') or exit('Access Denied');
+
+class MusicModuleProcessor extends WeModuleProcessor {
+	public function respond() {
+		global $_W;
+		$rid = $this->rule;
+		$item = table('music_reply')->where(array('rid' => $rid))->orderby('RAND()')->get();
+		if (empty($item['id'])) {
+			return false;
+		}
+		return $this->respMusic(array(
+			'Title' => $item['title'],
+			'Description' => $item['description'],
+			'MusicUrl' => $item['url'],
+			'HQMusicUrl' => $item['hqurl'],
+		));
+	}
+}

BIN
framework/builtin/news/icon.jpg


BIN
framework/builtin/news/preview.jpg


+ 60 - 0
framework/builtin/news/processor.php

xqd
@@ -0,0 +1,60 @@
+<?php
+/**
+ * [WeEngine System] Copyright (c) 2014 WE7.CC
+ * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
+ */
+defined('IN_IA') or exit('Access Denied');
+
+class NewsModuleProcessor extends WeModuleProcessor {
+	public function respond() {
+		global $_W;
+		$rid = $this->rule;
+		$commends = table('news_reply')
+			->where(array(
+				'rid' => $rid,
+				'parent_id' => -1
+			))
+			->orderby(array(
+				'displayorder' => 'DESC',
+				'id' => 'ASC'
+			))
+			->limit(8)
+			->getall();
+		if (empty($commends)) {
+			
+			$main = table('news_reply')
+				->where(array(
+					'rid' => $rid,
+					'parent_id' => 0
+				))
+				->orderby('RAND()')
+				->get();
+			if (empty($main['id'])) {
+				return false;
+			}
+			$commends = table('news_reply')
+				->where(array('id' => $main['id']))
+				->whereor(array('parent_id' => $main['id']))
+				->orderby(array(
+					'parent_id' => 'ASC',
+					'displayorder' => 'DESC',
+					'id' => 'ASC'
+				))
+				->getall();
+		}
+		if (empty($commends)) {
+			return false;
+		}
+		$news = array();
+		foreach ($commends as $c) {
+			$row = array();
+			$row['title'] = $c['title'];
+			$row['description'] = $c['description'];
+			!empty($c['thumb']) && $row['picurl'] = tomedia($c['thumb']);
+			$row['url'] = empty($c['url']) ? $this->createMobileUrl('detail', array('id' => $c['id'])) : $c['url'];
+			$news[] = $row;
+		}
+
+		return $this->respNews($news);
+	}
+}

+ 26 - 0
framework/builtin/news/site.php

xqd
@@ -0,0 +1,26 @@
+<?php
+/**
+ * [WeEngine System] Copyright (c) 2014 WE7.CC
+ * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
+ */
+defined('IN_IA') or exit('Access Denied');
+
+class NewsModuleSite extends WeModuleSite {
+	public function doMobileDetail() {
+		global $_W, $_GPC;
+		$id = intval($_GPC['id']);
+		$row = table('news_reply')->getById($id);
+		if (!empty($row['url'])) {
+			header('Location: ' . $row['url']);
+		}
+		$row = istripslashes($row);
+		$title = $row['title'];
+		
+		if ('android' == $_W['os'] && 'wechat' == $_W['container'] && $_W['account']['account']) {
+			$subscribeurl = "weixin://profile/{$_W['account']['account']}";
+		} else {
+			$subscribeurl = table('account_wechats')->where(array('uniacid' => intval($_W['uniacid'])))->getcolumn('subscribeurl');
+		}
+		include $this->template('detail');
+	}
+}

+ 88 - 0
framework/builtin/news/template/mobile/detail.html

xqd
@@ -0,0 +1,88 @@
+{template 'header'}
+<div id="activity-detail">
+<style type="text/css">
+@charset "utf-8";
+html{background:#FFF;color:#000;}
+body, div, dl, dt, dd, h1, h2, h3, h4, h5, h6, pre, code, form, fieldset, legend, input, textarea, p, blockquote, th, td{margin:0;padding:0;}
+table{border-collapse:collapse;border-spacing:0;}
+fieldset, img{border:0;}
+address, caption, cite, code, dfn,  th, var{font-style:normal;font-weight:normal;}
+ol, ul{list-style:none;}
+caption, th{text-align:left;}
+h1, h2, h3, h4, h5, h6{font-size:100%;font-weight:normal;}
+q:before, q:after{content:'';}
+abbr, acronym{border:0;font-variant:normal;}
+sup{vertical-align:text-top;}
+sub{vertical-align:text-bottom;}
+input, textarea, select{font-family:inherit;font-size:inherit;font-weight:inherit;}
+input, textarea, select{font-size:100%;}
+legend{color:#000;}
+html{background-color:#f8f7f5;}
+body{background:#f8f7f5;color:#222;font-family:Helvetica, STHeiti STXihei, Microsoft JhengHei, Microsoft YaHei, Tohoma, Arial;height:100%;position:relative;}
+body > .tips{display:none;left:50%;padding:20px;position:fixed;text-align:center;top:50%;width:200px;z-index:100;}
+.page{padding:15px;}
+.page .page-error, .page .page-loading{line-height:30px;position:relative;text-align:center;}
+
+#activity-detail .page-bizinfo{border-bottom:2px solid #EEE;}
+#activity-detail .page-bizinfo .header{padding: 15px 15px 10px; border-bottom:1px solid #CCC;}
+#activity-detail .page-bizinfo .header #activity-name{color:#000;font-size:20px;font-weight:bold;word-break:normal;word-wrap:break-word;}
+#activity-detail .page-bizinfo .header #post-date{color:#8c8c8c;font-size:11px;margin:0;}
+#activity-detail .page-content{padding:15px;}
+#activity-detail .page-content .media{margin-bottom:18px;}
+#activity-detail .page-content .media img{width:100%;}
+#activity-detail .page-content .text{color:#3e3e3e;font-size:1.5;line-height:1.5;width: 100%;overflow: hidden;zoom:1;}
+#activity-detail .page-content .text p{min-height:1.5em;min-height: 1.5em;word-wrap: break-word;word-break:break-all;}
+#activity-list .header{font-size:20px;}
+#activity-list .page-list{border:1px solid #ccc;border-radius:5px;margin:18px 0;overflow:hidden;}
+#activity-list .page-list .line.btn{border-radius:0;margin:0;text-align:left;}
+#activity-list .page-list .line.btn .checkbox{height:25px;line-height:25px;padding-left:35px;position:relative;}
+#activity-list .page-list .line.btn .checkbox .icons{background-color:#ccc;left:0;position:absolute;top:0;}
+#activity-list .page-list .line.btn.off .icons{background-image:none;}
+#activity-list #save.btn{background-image:linear-gradient(#22dd22, #009900);background-image:-moz-linear-gradient(#22dd22, #009900);background-image:-ms-linear-gradient(#22dd22, #009900);background-image:-o-linear-gradient(#22dd22, #009900);background-image:-webkit-gradient(linear, left top, left bottom, from(#22dd22), to(#009900));background-image:-webkit-linear-gradient(#22dd22, #009900);}
+.vm{vertical-align:middle;}
+.tc{text-align:center;}
+.db{display:block;}
+.dib{display:inline-block;}
+.b{font-weight:700;}
+.clr{clear:both;}
+.text img{max-width:100%;}
+.page-url{padding-top:18px;}
+.page-url-link{color:#607FA6;font-size:14px;text-decoration:none;text-shadow:0 1px #ffffff;-webkit-text-shadow:0 1px #ffffff;-moz-text-shadow:0 1px #ffffff;}
+#footer{text-align:center; background-color:#DADADA; border-top:1px solid #B9B9B9;}
+#footer .copyright{border-top: 1px solid #CACACA;color: #7B7B7B;height: 35px;line-height: 35px;font-size: 12px;}
+#footer .copyright a{display: block;width: 100%;height: 100%;}
+#mbutton{padding:15px 10px 15px 10px; overflow:hidden; border-bottom:1px #DDD solid;}
+#mbutton > span{float:right; display:inline-block; background:#58a3ff; border:1px #63a0eb solid; color:#FFF; height:30px; line-height:30px; padding:0 10px; margin-left:10px;}
+#mcover{position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(0, 0, 0, 0.7);display:none;z-index:20000;}
+#mcover img{position:fixed;right: 18px;top:5px;width:260px;height:180px;z-index:20001;}
+</style>
+<div class="page-bizinfo">
+	<div class="header">
+		<h1 id="activity-name">{$row['title']}</h1>
+		<span id="post-date">
+			<span>{php echo date('Y-m-d', $row['createtime'])}</span>
+			<span>{$row['author']}</span>
+			<a href="{$subscribeurl}">
+				{if empty($_W['account']['name'])}
+					微擎团队
+				{else}
+					{$_W['account']['name']}
+				{/if}
+			</a>
+		</span>
+	</div>
+</div>
+
+<div class="page-content">
+	{if $row['incontent'] != 0}
+		<div class="media">
+			<img onerror="this.parentNode.removeChild(this)" src="{php echo tomedia($row['thumb']);}">
+		</div>
+	{/if}
+	<div class="text">
+		{$row['content']}
+	</div>
+</div>
+</div>
+{php $_share = array('content' => $row['description'], 'title' => $row['title'], 'imgUrl' => tomedia($row['thumb']));}
+{template 'footer'}

BIN
framework/builtin/paycenter/icon.jpg


+ 25 - 0
framework/builtin/paycenter/inc/mobile/cardconsume.inc.php

xqd
@@ -0,0 +1,25 @@
+<?php
+
+defined('IN_IA') or exit('Access Denied');
+global $_W, $_GPC;
+load()->model('activity');
+$op = !empty($_GPC['op']) ? safe_gpc_string($_GPC['op']) : 'consume';
+$user_permission = permission_account_user('system');
+if ('consume' == $op) {
+	$type = intval($_GPC['type']);
+	$qrcode = safe_gpc_string($_GPC['code']);
+	if ($_W['isajax']) {
+		$code = safe_gpc_string($_GPC['code']);
+		$record = pdo_get('coupon_record', array('code' => $code));
+		if (empty($record)) {
+			message(error(-1, '卡券记录不存在'), '', 'ajax');
+		}
+		$status = activity_coupon_use($record['couponid'], $record['id'], 'paycenter');
+		if (!is_error($status)) {
+			message(error('0', ''), '', 'ajax');
+		} else {
+			message(error('-1', $status['message']), '', 'ajax');
+		}
+	}
+}
+include $this->template('cardconsume');

+ 13 - 0
framework/builtin/paycenter/inc/mobile/more.inc.php

xqd
@@ -0,0 +1,13 @@
+<?php
+
+defined('IN_IA') or exit('Access Denied');
+global $_W, $_GPC;
+paycenter_check_login();
+$user_permission = permission_account_user('system');
+$store_name = $_W['user']['store_name'];
+$clerk_name = $_W['user']['name'];
+if ('more' == $_GPC['do']) {
+	$clerk_info = table('mc_members')->select('mobile')->where(array('uid' => $_W['user']['uid']))->get();
+}
+
+include $this->template('more');

+ 77 - 0
framework/builtin/paycenter/inc/mobile/scanpay.inc.php

xqd
@@ -0,0 +1,77 @@
+<?php
+
+defined('IN_IA') or exit('Access Denied');
+global $_W, $_GPC;
+paycenter_check_login();
+$user_permission = permission_account_user('system');
+$op = !empty($_GPC['op']) ? safe_gpc_string($_GPC['op']) : 'index';
+if ($_W['account']['level'] != ACCOUNT_SERVICE_VERIFY) {
+	message('公众号权限不足', '', 'error');
+}
+if ('post' == $op) {
+	if (checksubmit()) {
+		$fee = !empty($_GPC['fee']) ? safe_gpc_string($_GPC['fee']) : message('收款金额有误', '', 'error');
+		$body = !empty($_GPC['body']) ? safe_gpc_string($_GPC['body']) : '收银台收款' . $fee;
+		$data = array(
+			'uniacid' => $_W['uniacid'],
+			'clerk_id' => $_W['user']['clerk_id'],
+			'clerk_type' => $_W['user']['clerk_type'],
+			'store_id' => $_W['user']['store_id'],
+			'body' => $body,
+			'fee' => $fee,
+			'final_fee' => $fee,
+			'credit_status' => 1,
+			'createtime' => TIMESTAMP,
+		);
+		table('paycenter_order')->fill($data)->save();
+		$id = pdo_insertid();
+		header('location:' . $this->createMobileUrl('scanpay', array('op' => 'qrcode', 'id' => $id)));
+		die;
+	}
+}
+
+if ('qrcode' == $op) {
+	$id = intval($_GPC['id']);
+	$order = table('paycenter_order')->getById($id, $_W['uniacid']);
+	if (empty($order)) {
+		message('订单不存在或已删除', '', 'error');
+	}
+	if (1 == $order['status']) {
+		message('该订单已付款', '', 'error');
+	}
+}
+
+if ('list' == $op) {
+	$period = intval($_GPC['period']);
+	$where = array(
+		'uniacid' => $_W['uniacid'],
+		'status' => 1,
+		'clerk_id' => $_W['user']['clerk_id'],
+	);
+	if ($period <= 0) {
+		$starttime = strtotime(date('Y-m-d')) + $period * 86400;
+		$endtime = $starttime + 86400;
+		$where['paytime >='] = $starttime;
+		$where['paytime <='] = $endtime;
+	}
+	$orders = table('paycenter_order')
+		->where($where)
+		->orderby(array('paytime' => 'DESC'))
+		->getall();
+}
+
+if ('detail' == $op) {
+	$id = intval($_GPC['id']);
+	$order = table('paycenter_order')->getById($id, $_W['uniacid']);
+	if (empty($order)) {
+		message('订单不存在', '', '');
+	} else {
+		$store_id = $order['store_id'];
+		$types = paycenter_order_types();
+		$trade_types = paycenter_order_trade_types();
+		$status = paycenter_order_status();
+		$store_info = pdo_get('activity_stores', array('id' => $store_id, 'uniacid' => $_W['uniacid']), array('business_name'));
+	}
+}
+
+include $this->template('scanpay');

+ 1 - 0
framework/builtin/paycenter/inc/model.php

xqd
@@ -0,0 +1 @@
+ 

+ 73 - 0
framework/builtin/paycenter/module.php

xqd
@@ -0,0 +1,73 @@
+<?php
+/**
+ * [WeEngine System] Copyright (c) 2014 WE7.CC
+ * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
+ */
+defined('IN_IA') or exit('Access Denied');
+
+class PaycenterModule extends WeModule {
+	public $tablename = 'wxcard_reply';
+	public $replies = array();
+
+	public function fieldsFormDisplay($rid = 0) {
+		if (!empty($rid)) {
+			$replies = table($this->tablename)->where(array('rid' => $rid))->getall();
+		}
+		include $this->template('display');
+	}
+
+	public function fieldsFormValidate($rid = 0) {
+		global $_GPC;
+		$this->replies = @json_decode(htmlspecialchars_decode($_GPC['replies']), true);
+		if (empty($this->replies)) {
+			return '必须填写有效的回复内容.';
+		}
+		foreach ($this->replies as $k => &$row) {
+			if (empty($row['cid']) || empty($row['card_id'])) {
+				unset($k);
+			}
+		}
+		if (empty($this->replies)) {
+			return '必须填写有效的回复内容.';
+		}
+
+		return '';
+	}
+
+	public function fieldsFormSubmit($rid = 0) {
+		global $_W, $_GPC;
+		$rid = intval($rid);
+		$rule_exists = table('rule')->getById($rid, $_W['uniacid']);
+		if (empty($rule_exists)) {
+			return false;
+		}
+		table($this->tablename)->where(array('rid' => $rid))->delete();
+		foreach ($this->replies as $reply) {
+			$data = array(
+				'rid' => $rid,
+				'title' => $reply['title'],
+				'card_id' => $reply['card_id'],
+				'cid' => $reply['cid'], 
+				'brand_name' => $reply['brand_name'],
+				'logo_url' => $reply['logo_url'],
+				'success' => safe_gpc_string($_GPC['success']),
+				'error' => safe_gpc_string($_GPC['error']),
+			);
+			table($this->tablename)->fill($data)->save();
+		}
+
+		return true;
+	}
+
+	public function ruleDeleted($rid = 0) {
+		global $_W;
+		$rid = intval($rid);
+		$rule_exists = table('rule')->getById($rid, $_W['uniacid']);
+		if (empty($rule_exists)) {
+			return false;
+		}
+		table($this->tablename)->where(array('rid' => $rid))->delete();
+
+		return true;
+	}
+}

BIN
framework/builtin/paycenter/preview.jpg


+ 64 - 0
framework/builtin/paycenter/processor.php

xqd
@@ -0,0 +1,64 @@
+<?php
+/**
+ * [WeEngine System] Copyright (c) 2014 WE7.CC
+ * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
+ */
+defined('IN_IA') or exit('Access Denied');
+
+class PaycenterModuleProcessor extends WeModuleProcessor {
+	public function respond() {
+		global $_W;
+		$rid = $this->rule;
+		$reply = table('wxcard_reply')
+			->where(array('rid' => $rid))
+			->orderby('RAND()')
+			->get();
+		if (empty($reply)) {
+			return false;
+		}
+		load()->classs('weixin.account');
+		load()->classs('coupon');
+		$coupon = new coupon($_W['acid']);
+		if (is_error($coupon)) {
+			$this->error($reply, $coupon['message']);
+			die;
+		}
+		$card = $coupon->BuildCardExt($reply['cid']);
+		if (is_error($card)) {
+			$this->error($reply, $card['message']);
+			die;
+		}
+		$data = array(
+			'touser' => $_W['openid'],
+			'msgtype' => 'wxcard',
+			'wxcard' => array(
+				'card_id' => $card['card_id'],
+				'card_ext' => $card['card_ext'],
+			),
+		);
+		$acc = WeAccount::createByUniacid();
+		$status = $acc->sendCustomNotice($data);
+		if (is_error($status)) {
+			$this->error($reply, $status['message']);
+			die;
+		}
+		if (!empty($reply['success'])) {
+			return $this->respText($reply['success']);
+			die;
+		}
+
+		return true;
+	}
+
+	public function error($reply, $msg) {
+		if (empty($reply['error'])) {
+			if (empty($msg)) {
+				return true;
+			}
+
+			return $this->respText($msg);
+		} else {
+			return $this->respText($reply['error']);
+		}
+	}
+}

+ 271 - 0
framework/builtin/paycenter/site.php

xqd
@@ -0,0 +1,271 @@
+<?php
+/**
+ * [WeEngine System] Copyright (c) 2014 WE7.CC
+ * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
+ */
+defined('IN_IA') or exit('Access Denied');
+class PaycenterModuleSite extends WeModuleSite {
+	public function __construct() {
+		global $_W, $_GPC;
+		load()->model('paycenter');
+		if ('pay' != $_GPC['do'] && 'consume' != $_GPC['do']) {
+			$session = json_decode(base64_decode($_GPC['_pc_session']), true);
+			if (is_array($session)) {
+				load()->model('user');
+				$user = user_single(array('uid' => $session['uid']));
+				if (is_array($user) && $session['hash'] === $user['hash']) {
+					$clerk = table('activity_clerks')->getByUid($user['uid'], $_W['uniacid']);
+					if (empty($clerk)) {
+						message('您没有管理该店铺的权限', referer(), 'error');
+					}
+					$_W['uid'] = $user['uid'];
+					$_W['username'] = $user['username'];
+					$_W['user'] = $user;
+				} else {
+					isetcookie('_pc_session', false, -100);
+				}
+				unset($user);
+			}
+			if (empty($_W['user']) && $_W['openid'] && '1' != $_GPC['_wechat_logout']) {
+				$clerk = table('activity_clerks')->getByOpenid($_W['openid'], $_W['uniacid']);
+				if (!empty($clerk)) {
+					$user = table('users')->where(array('uid' => $clerk['uid']))->get();
+					if (!empty($user)) {
+						$cookie = array();
+						$cookie['uid'] = $user['uid'];
+						$cookie['username'] = $user['username'];
+						$cookie['hash'] = md5($user['password'] . $user['salt']);
+						$session = base64_encode(json_encode($cookie));
+						isetcookie('_pc_session', $session, !empty($_GPC['rember']) ? 7 * 86400 : 0, true);
+						$_W['uid'] = $user['uid'];
+						$_W['username'] = $user['username'];
+						$_W['user'] = $user;
+					}
+				}
+			}
+		}
+	}
+
+	public function doMobileLogin() {
+		global $_W, $_GPC;
+		if (!empty($_W['user'])) {
+			header('Location:' . $this->createMobileUrl('home'));
+			die;
+		}
+		if ($_W['isajax']) {
+			load()->model('user');
+			$user['username'] = safe_gpc_string($_GPC['username']);
+			$user['password'] = safe_gpc_string($_GPC['password']);
+
+			$user = user_single($user);
+			if (empty($user)) {
+				message(error(-1, '账号或密码错误'), '', 'ajax');
+			}
+			if (1 == $user['status']) {
+				message(error(-1, '您的账号正在审核或是已经被系统禁止,请联系网站管理员解决'), '', 'ajax');
+			}
+			$clerk = table('activity_clerks')->getByUid($user['uid'], $_W['uniacid']);
+			if (empty($clerk)) {
+				message(error(-1, '您没有管理该店铺的权限'), '', 'ajax');
+			}
+			$cookie = array();
+			$cookie['uid'] = $user['uid'];
+			$cookie['hash'] = $user['hash'];
+			$session = base64_encode(json_encode($cookie));
+			isetcookie('_pc_session', $session, !empty($_GPC['rember']) ? 7 * 86400 : 0, true);
+			message(error(0, ''), '', 'ajax');
+		}
+		include $this->template('login');
+	}
+
+	public function doMobileLogout() {
+		isetcookie('_pc_session', '', -10000);
+		isetcookie('_wechat_logout', '1', 180);
+		$forward = safe_gpc_string($_GPC['forward']);
+		if (empty($forward)) {
+			$forward = './?refersh';
+		}
+		header('Location:' . $this->createMobileUrl('login'));
+		die;
+	}
+
+	public function doMobileHome() {
+		global $_W, $_GPC;
+		paycenter_check_login();
+		$user_permission = permission_account_user('system');
+		$today_revenue = $this->revenue(0);
+		$yesterday_revenue = $this->revenue(-1);
+		$seven_revenue = $this->revenue(-7);
+		include $this->template('home');
+	}
+
+	
+	public function revenue($period) {
+		global $_W;
+		if ('0' == $period) {
+			$starttime = strtotime(date('Y-m-d'));
+			$endtime = $starttime + 86400;
+		} else {
+			$starttime = strtotime(date('Y-m-d', strtotime($period . 'day')));
+			$endtime = strtotime(date('Y-m-d'));
+		}
+		$revenue = table('paycenter_order')
+			->where(array(
+				'uniacid' =>  $_W['uniacid'],
+				'status' => 1,
+				'paytime >=' => $starttime,
+				'paytime <=' => $endtime,
+				'clerk_id' => intval($_W['user']['clerk_id'])
+			))
+			->getcolumn('SUM(final_fee)');
+		return floatval($revenue);
+	}
+
+	public function doMobilePay() {
+		global $_W, $_GPC;
+		$id = intval($_GPC['id']);
+		$order = table('paycenter_order')->getById($id, $_W['uniacid']);
+
+		if (empty($order)) {
+			message('订单不存在或已删除', '', 'error');
+		}
+		if (1 == $order['status']) {
+			message('该订单已付款', '', 'error');
+		}
+		if (!empty($_W['member']['uid']) || !empty($_W['fans'])) {
+			$update = array(
+				'uid' => $_W['member']['uid'],
+				'openid' => $_W['openid'],
+				'nickname' => $_W['fans']['nickname'],
+			);
+			table('paycenter_order')
+				->where(array(
+					'uniacid' => $_W['uniacid'],
+					'id' => $id
+				))
+				->fill($update)
+				->save();
+			$order['uid'] = $_W['member']['uid'];
+		}
+		$params['module'] = 'paycenter_order';
+		$params['tid'] = $order['id'];
+		$params['ordersn'] = $order['id'];
+		$params['user'] = $order['uid'];
+		$params['fee'] = $order['final_fee'];
+		$params['title'] = $_W['account']['name'] . $order['body'] ? $order['body'] : '收银台收款';
+		$this->pay($params);
+	}
+
+	public function payResult($params) {
+		global $_W;
+		if ('success' == $params['result'] && 'notify' == $params['from']) {
+			$order = table('paycenter_order')->getById($params['tid'], $_W['uniacid']);
+			if (!empty($order)) {
+				if (!empty($params['tag'])) {
+					$params['tag'] = iunserializer($params['tag']);
+				}
+				$data = array(
+					'type' => $params['type'],
+					'trade_type' => strtolower($params['trade_type']),
+					'status' => 1,
+					'paytime' => TIMESTAMP,
+					'uniontid' => $params['tag']['uniontid'],
+					'transaction_id' => $params['tag']['transaction_id'],
+					'follow' => intval($params['follow']),
+					'final_fee' => $params['card_fee'],
+				);
+				if ('credit' == $params['type']) {
+					$data['credit2'] = $params['card_fee'];
+				} else {
+					$data['cash'] = $params['card_fee'];
+				}
+				if (1 == $params['is_usecard']) {
+					$discount_fee = $order['fee'] - $params['card_fee'];
+					$data['remark'] = "使用优惠券减免{$discount_fee}元";
+				}
+				table('paycenter_order')
+					->where(array(
+						'id' => $params['tid'],
+						'uniacid' => $_W['uniacid']
+					))
+					->fill($data)
+					->save();
+
+				$cash_data = array(
+						'uniacid' => $_W['uniacid'],
+						'uid' => $order['uid'],
+						'fee' => $order['fee'],
+						'final_fee' => $order['final_fee'],
+						'credit1' => $order['credit1'],
+						'credit1_fee' => $order['credit1_fee'],
+						'credit2' => $order['credit2'],
+						'cash' => $params['card_fee'],
+						'final_cash' => $params['card_fee'],
+						'return_cash' => 0,
+						'remark' => $order['remark'],
+						'clerk_id' => $order['clerk_id'],
+						'store_id' => $order['store_id'],
+						'clerk_type' => $order['clerk_type'],
+						'createtime' => TIMESTAMP,
+				);
+				table('mc_cash_record')->fill($cash_data)->save();
+			}
+		}
+		if ('success' == $params['result'] && 'return' == $params['from']) {
+			message('支付成功!', $this->createMobileUrl('paydetail', array('id' => $params['tid'])), 'success');
+		}
+	}
+
+	public function doMobilePayDetail() {
+		global $_W, $_GPC;
+		$id = intval($_GPC['id']);
+		$order = table('paycenter_order')->getById($id, $_W['uniacid']);
+		if (empty($order)) {
+			message('订单不存在或已删除', '', 'error');
+		}
+		if ($order['store_id'] > 0) {
+			$store = pdo_get('activity_stores', array('id' => $order['store_id']), array('business_name'));
+		}
+		include $this->template('paydetail');
+	}
+
+	public function doMobileSelfpay() {
+		global $_W, $_GPC;
+		if (checksubmit()) {
+			$fee = !empty($_GPC['fee']) ? safe_gpc_string($_GPC['fee']) : message('收款金额有误', '', 'error');
+			$body = !empty($_GPC['body']) ? safe_gpc_string($_GPC['body']) : '收银台收款' . safe_gpc_string($_GPC['fee']);
+			$openid = !empty($_GPC['openid']) ? safe_gpc_string($_GPC['openid']) : message('用户信息错误', '', 'error');
+			$clerk = table('activity_clerks')->getById(intval($_GPC['clerk_id']), $_W['uniacid']);
+			$data = array(
+				'uniacid' => $_W['uniacid'],
+				'openid' => $openid,
+				'nickname' => safe_gpc_string($_GPC['nickname']),
+				'uid' => $_W['member']['uid'],
+				'clerk_id' => $clerk['id'],
+				'clerk_type' => 3,
+				'store_id' => $clerk['storeid'],
+				'body' => $body,
+				'fee' => $fee,
+				'final_fee' => $fee,
+				'credit_status' => 1,
+				'createtime' => TIMESTAMP,
+			);
+			table('paycenter_order')->fill($data)->save();
+			$id = pdo_insertid();
+			header('location:' . $this->createMobileUrl('pay', array('id' => $id)));
+			die;
+		}
+		$fans = mc_oauth_userinfo();
+		if (is_error($fans) || empty($fans)) {
+			message('获取粉丝信息失败', '', 'error');
+		}
+		include $this->template('selfpay');
+	}
+
+	public function doMobileConsume() {
+		global $_GPC, $_W;
+		$url = murl('entry', array('m' => 'we7_coupon', 'do' => 'consume', 'card_id' => intval($_GPC['card_id']), 'encrypt_code' => safe_gpc_string($_GPC['encrypt_code']), 'openid' => safe_gpc_string($_GPC['openid'])));
+		header("Location: $url");
+		exit;
+	}
+}

+ 148 - 0
framework/builtin/paycenter/template/display.html

xqd
@@ -0,0 +1,148 @@
+{php load()->func('tpl')}
+<style>
+	.wxcard{clear: both;margin-bottom: 20px; position: relative;}
+	.wxcard .panel-body .panel-wxcard {position:relative;}
+	.wxcard .panel-body .panel-wxcard .wxcard-content{width:100%; height:90px; border-radius:5px; border-bottom-left-radius:0; border-bottom-right-radius:0; border:1px solid #e7e7eb; border-bottom:0; position:relative; background-color:#A9D92C; color:#fff; font-size:16px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis;}
+	.wxcard .panel-body .panel-wxcard .wxcard-content img{width:60px; height:60px; position:absolute; top:15px; left:15px;}
+	.wxcard .panel-body .panel-wxcard .wxcard-content .title{position:absolute; left:90px; top:30px; font-size:19px}
+	.wxcard .panel-body .panel-wxcard .wxcard-footer{background-color:#fff; height:35px; line-height:35px; border:1px solid #e7e7eb; padding:0 10px; border-bottom-left-radius:5px; border-bottom-right-radius:5px;}
+	.wxcard .panel-body .mask{position:absolute; width:100%; height:100%; line-height:104px; left:0; top:0; z-index:999; background-color:rgba(229, 229, 229, 0.85) !important; text-align:center; display:none;}
+
+	.wxcard .panel-body:hover .mask{display:block}
+	.wxcard .del,.panel .no{position: absolute; top:-10px; width:20px; height:20px; color:#fff; background:rgba(0,0,0,0.3); text-align:center; line-height:20px; cursor:pointer; border-radius:100%;}
+	.wxcard .del{right:-10px;}
+	.wxcard .no{left:-10px;background: #3071a9}
+	.wxcard .del:hover{background:rgba(0,0,0,0.7);}
+	.wxcard .panel:last-child{margin-bottom: 0;}
+</style>
+<div class="alert alert-info" style="margin-top:-20px">
+	<i class="fa fa-info-circle"></i> 您可以添加多个回复卡券,系统将随机选择一个卡券推送给粉丝<br>
+	<i class="fa fa-info-circle"></i> 设置为回复的卡券要保证是可用的卡券.卡券的库存应该足够大,使用期限应该有效<br>
+</div>
+<input type="hidden" name="replies" value="">
+<div class="panel panel-default clearfix">
+	<div class="panel-heading">回复内容</div>
+	<div class="panel-body">
+		<div class="row clearfix">
+			<div class="col-xs-6 col-sm-3 col-md-3">
+				<div class="panel panel-default">
+					<div class="panel-body">
+						<div class="form-group" style="margin:-15px">
+							<label class="col-xs-12 control-label" style="text-align:left; padding-bottom:7px">卡券发送成功提示语</label>
+							<div class="col-xs-12">
+								<textarea class="form-control" name="success">{$replies[0]['success']}</textarea>
+							</div>
+						</div>
+						<div class="form-group" style="margin:-15px">
+							<label class="col-xs-12 control-label" style="text-align:left; padding-bottom:7px">卡券发送失败提示语</label>
+							<div class="col-xs-12">
+								<textarea class="form-control" name="error">{$replies[0]['error']}</textarea>
+							</div>
+						</div>
+					</div>
+				</div>
+				<div class="panel panel-default wxcard" ng-repeat="item in context.items">
+					<div class="panel-body">
+						<div class="panel-wxcard">
+							<div class="wxcard-content" ng-style="{'background-color' : item.color}">
+								<img src="" ng-src="{{item.logo_url}}" class="img-circle">
+								<div class="title">{{item.title}}</div>
+							</div>
+							<div class="wxcard-footer clearfix">
+								<div class="pull-right text-muted hide">2015-12-5</div>
+								<div>{{item.brand_name}}</div>
+							</div>
+							<div class="mask">
+								<a href="javascript:;" ng-click="context.selectCoupon(item)"><i class="fa fa-book"></i> 选择微信卡券</a>
+							</div>
+						</div>
+					</div>
+					<div class="no">{{$index + 1}}</div>
+					<div class="del" ng-click="context.removeItem(item);"><i class="fa fa-times"></i></div>
+				</div>
+				<div class="btn btn-primary" ng-click="context.addItem()" style="margin-bottom:20px">添加一组回复</div>
+			</div>
+		</div>
+	</div>
+</div>
+<script>
+	window.initReplyController = function($scope, $http) {
+		$scope.context = {};
+		$scope.context.items = {php echo json_encode($replies)};
+		if(!$.isArray($scope.context.items)) {
+			$scope.context.items = [];
+		}
+
+		$scope.context.addItem = function(){
+			$scope.context.items.push(
+				{
+					id: '',
+					title: '',
+					logo_url: '',
+					color: '',
+					brand_name: ''
+				}
+			);
+			$scope.context.activeIndex = $scope.context.items.length - 1;
+			$scope.context.activeItem = $scope.context.items[$scope.context.activeIndex];
+		}
+
+		if($scope.context.items.length == 0) {
+			$scope.context.addItem();
+		}
+		$scope.context.activeIndex = 0;
+		$scope.context.activeItem = $scope.context.items[$scope.context.activeIndex];
+
+		$scope.context.removeItem = function(item){
+			if($scope.context.items.length == 1) {
+				util.message('至少有一组回复内容');
+				return false;
+			}
+			$scope.context.items = _.without($scope.context.items, item);
+			$scope.context.activeIndex = 0;
+			$scope.context.activeItem = $scope.context.items[$scope.context.activeIndex];
+			$scope.$digest();
+		}
+
+		$scope.context.selectCoupon = function(item) {
+			var index = $.inArray(item, $scope.context.items);
+			if(index == -1) return false;
+			$scope.context.activeIndex = index;
+			$scope.context.activeItem = $scope.context.items[$scope.context.activeIndex];
+
+			var option = {
+				'ignore' : {
+					'local' : true
+				}
+			};
+			util.coupon(function(coupon){
+				$scope.context.activeItem.card_id = coupon.card_id;
+				$scope.context.activeItem.cid = coupon.id;
+				$scope.context.activeItem.title = coupon.title;
+				$scope.context.activeItem.logo_url = coupon.logo_url;
+				$scope.context.activeItem.brand_name = coupon.brand_name;
+				$scope.$digest();
+			}, option);
+		};
+	};
+
+	window.validateReplyForm = function(form, $, _, util, $scope) {
+		if($scope.context.items.length == 0) {
+			util.message('没有回复内容', '', 'error');
+			return false;
+		}
+		var error = {empty: false, message: ''};
+		angular.forEach($scope.context.items, function(v, k){
+			if($.trim(v.cid) == '' || $.trim(v.card_id) == '') {
+				this.empty = true;
+			}
+		}, error);
+		if(error.empty) {
+			util.message('存在没有设置 "卡券" 的回复条目');
+			return false;
+		}
+		var val = angular.toJson($scope.context.items);
+		$(':hidden[name=replies]').val(val);
+		return true;
+	};
+</script>

+ 39 - 0
framework/builtin/paycenter/template/mobile/cardconsume.html

xqd
@@ -0,0 +1,39 @@
+{php define(MUI, true);}
+{template 'common/header'}
+<header class="mui-bar mui-bar-nav">
+	<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
+	<h1 class="mui-title">卡券核销</h1>
+</header>
+{template 'nav'}
+<div class="mui-content">
+	<form action="" method="post" class="mui-mt15">
+		<div class="mui-input-group">
+			<div class="mui-input-row">
+				<input type="text" name="code" value="{$qrcode}" placeholder="请输入序列号"/>
+			</div>
+		</div>
+		<div class="mui-content-padded">
+			<button class="mui-btn mui-btn-success mui-btn-block syscard-check">核 销</button>
+		</div>
+	</form>
+</div>
+<script type="text/javascript">
+	$('.syscard-check').click(function(){
+		var code = $.trim($('input[name="code"]').val());
+		if(!code) {
+			alert('code号错误');
+			return false;
+		}
+		$.post("{php echo $this->createMobileUrl('cardconsume', array('op' => 'consume'));}", {code:code}, function(data) {
+			var data = $.parseJSON(data);
+			if(data.message.errno == -1) {
+				alert(data.message.message);
+			} else {
+				alert('核销成功');
+				location.href = "{php echo $this->createMobileUrl('home')}";
+			}
+		});
+		return false; 
+	});
+</script>
+{template 'common/footer'}

+ 101 - 0
framework/builtin/paycenter/template/mobile/consume.html

xqd
@@ -0,0 +1,101 @@
+{php define(MUI, true);}
+{template 'common/header'}
+<style>
+	ul,li {padding:0; margin:0; border:0;}
+	body{background:#d2e6e9; padding-bottom:63px;}
+	.btn-group-top-box{padding:10px 0; border-bottom:1px solid #a5d7de; font-family:Helvetica, Arial, sans-serif; text-align:center; width:100%;}
+	.btn-group-top{overflow:hidden;}
+	.btn-group-top .btn{ -webkit-box-shadow:none; box-shadow:none; border-color:#5ac5d4; color:#5ac5d4; background:#d1e5e9; padding:6px;}
+	.btn-group-top .btn:hover{color:#FFF; background:#addbe1;}
+	.btn-group-top .btn.active{color:#FFF; background:#5ac5d4;}
+	.btn.use{background:#56c6d6; color:#FFF; border:0; border-radius:4px;}
+
+	.card-container{width:100%;max-width:640px;margin:0px auto;border-bottom:1px solid #a5d7de;}
+	.card-list{width:100%;margin:10px 0;padding:0 13px}
+	.card-list .top{height:60px;line-height:60px;background:#a9d92d url(./resource/images/card_tpl.png) repeat-x 0 bottom;border-top-left-radius:5px;border-top-right-radius:5px;}
+	.card-list .top .img{float:left;padding:0 10px}
+	.card-list .top .img img{width:40px;height:40px;border-radius:35px;}
+	.card-list .top .title{float:left;color:#FFF;font-weight:bold;font-size:16px;letter-spacing:1px}
+	.card-list .bottom{color:#b7b7b7;height:30px;line-height:30px;background:#FFF;padding:0 6px;border-bottom-left-radius:5px;border-bottom-right-radius:5px;}
+	.card-list .bottom .left-info{float:left;width:50%;overflow:hidden;}
+	.card-list .bottom .right-info{float:right;width:50%;overflow:hidden;text-align:right;}
+	.no-info{width:100%;padding:0 20px;text-align:center;height:40px;line-height:40px;color:#5ac5d4}
+	.page{width:100%;margin:0 auto;text-align:center;}
+	.page .pagination{padding:0;margin:0;}
+	.page .pagination a{color:#5ac5d4;background:#d2e6e9;border:1px solid #a5d7de;}
+	.page .pagination a:hover{color:#FFF;background:#addbe1;border:1px solid #a5d7de;}
+
+	.card-info .card-top{ position:relative; width:100%; color:#fff; background-color:#a9d92d; padding:21px 12px 12px;}
+	.card-top .logo img{width:38px; height:38px; border-radius:100%; margin-right:10px;}
+	.card-top .title{font-size:24px; margin-bottom:10px;}
+	.card-top .sub-title{margin-bottom:10px;}
+	.card-top .border-img{position: absolute; bottom: -1px; left: 0; width: 100%; height: 5px; background: url(./resource/images/card_tpl.png) repeat-x;}
+	.card-bottom{background:#fff; margin-bottom:15px; text-align:center; padding:15px 0;}
+	.card-bottom .bar-code img{width:100%; height:auto; margin-bottom:5px;}
+	.card-bottom .tips{margin:10px 0;}
+	.wx-card .operate{background:#fff; padding:15px 10px;}
+	.wx-card .operate input{margin-bottom:5px;}
+</style>
+<form action="" method="post" id="form1">
+	<input type="hidden" name="token" value="{$_W['token']}"/>
+	<input type="hidden" name="code" value="{$code['code']}"/>
+	<div class="wx-card">
+		<div class="card-info">
+			<div class="card-top" style="background: {$colors[$card['color']]}">
+				<div class="logo">
+					<img src="{$card['logo_url']}" alt="" class="img-circle">
+					<span>{$card['brand_name']}</span>
+				</div>
+				<div class="title mui-text-center">{$card['title']}</div>
+				<div class="sub-title mui-text-center">{$card['sub_title']}</div>
+				<div class="date mui-text-center">
+					{if $card['date_info']['time_type'] == 1}
+					有效期:{$card['date_info']['time_limit_start']}~{$card['date_info']['time_limit_end']}
+					{else}
+					有效期:领取后{$card['date_info']['deadline']}天后生效,{$card['date_info']['limit']}天有效
+					{/if}
+				</div>
+				<div class="border-img"></div>
+			</div>
+			<div class="card-bottom">
+				{if $error_code == 1}
+				<div class="text-muted">code码错误</div>
+				{else}
+				<div class="qrcode-block" data-url="{php echo murl('entry', array('m' => 'paycenter', 'do' => 'cardconsume', 'op' => 'consume', 'code' => $code), true, true);}" style="margin-top:20px"></div>
+				<div class="text-muted">店员可使用微信扫描上面二维码进行核销</div>
+				<div class="text-muted">code码:{$code}</div>
+				{/if}
+				<div class="tips hide">{$card['notice']}</div>
+			</div>
+		</div>
+		<div class="operate">
+			{if $error_code == 1}
+			<a class="btn btn-danger btn-block" disabled>code码错误</a>
+			{else}
+			<input type="password" id="password" name="password" class="form-control" placeholder="请输入店员密码" style="margin-bottom:20px">
+			<input type="submit" class="btn btn-success btn-block" name="submit" value="确定核销"/>
+			{/if}
+		</div>
+	</div>
+</form>
+<script>
+	require(['jquery.qrcode'], function(){
+		var url = $('.qrcode-block').data('url');
+		$('.qrcode-block').html('').qrcode({
+			render: 'canvas',
+			width: 150,
+			height: 150,
+			text: url
+		});
+	});
+	require(['util'], function(u){
+		$('#form1').submit(function(){
+			if(!$.trim($('#password').val())) {
+				u.message('请输入店员密码');
+				return false;
+			}
+			return true;
+		});
+	});
+</script>
+{template 'common/footer'}

+ 74 - 0
framework/builtin/paycenter/template/mobile/home.html

xqd
@@ -0,0 +1,74 @@
+{php define(MUI, true);}
+{template 'common/header'}
+<header class="mui-bar mui-bar-nav">
+	<h1 class="mui-title">{$_W['user']['store_name']}</h1>
+</header>
+{template 'nav'}
+<div class="mui-content paycenter">
+	<div class="mui-banner">
+		<img src="./resource/images/avatar.png" alt="" class="mui-logo mui-img-circle"/>
+		<h1 class="mui-name">{$_W['user']['name']}</h1>
+	</div>
+	<div class="mui-table activity-nav">
+		<div class="mui-table-cell">
+			<span class="mui-block">{$seven_revenue}</span>
+			<div>七日营收</div>
+		</div>
+		<div class="mui-table-cell">
+			<span class="mui-block">{$yesterday_revenue}</span>
+			<div>昨日营收</div>
+		</div>
+		<div class="mui-table-cell">
+			<span class="mui-block">{$today_revenue}</span>
+			<div>今日营收</div>
+		</div>
+	</div>
+	<ul class="mui-table-view mui-grid-view mui-grid-9 store-nav">
+		{if $_W['user']['clerk_type'] == 2 || ($_W['user']['clerk_type'] == 3 && in_array('coupon_consume', $user_permission))}
+		<li class="mui-table-view-cell mui-media mui-col-xs-4">
+			<a href="{php echo $this->createMobileUrl('cardconsume', array('op' => 'consume'));}">
+				<span class="mui-icon mui-img-circle mui-image"><img src="./resource/images/icon-verification.png" alt="" /></span>
+				<div class="mui-media-body">卡券核销</div>
+			</a>
+		</li>
+		{/if}
+		{if $_W['account']['level'] == ACCOUNT_SERVICE_VERIFY}
+		<li class="mui-table-view-cell mui-media mui-col-xs-4">
+			<a href="{php echo $this->createMobileUrl('scanpay', array('op' => 'index'));}">
+				<span class="mui-icon mui-img-circle mui-image"><img src="./resource/images/icon-qrcode.png" alt="" /></span>
+				<div class="mui-media-body">扫码收款</div>
+			</a>
+		</li>
+		{/if}
+		
+		<li class="mui-table-view-cell mui-media mui-col-xs-4">
+			<a href="{php echo $this->createMobileUrl('scanpay', array('op' => 'list', 'period' => '1'));}">
+				<span class="mui-icon mui-img-circle mui-image"><img src="./resource/images/icon-chart.png" alt="" /></span>
+				<div class="mui-media-body">收款记录</div>
+			</a>
+		</li>
+
+		{if $_W['container'] == 'wechat'}
+		<li class="mui-table-view-cell mui-media mui-col-xs-4">
+			<a href="javascript:;" id="scanqrcode">
+				<span class="mui-icon mui-img-circle mui-image"><img src="./resource/images/icon-chart.png" alt="" /></span>
+				<div class="mui-media-body">扫一扫</div>
+			</a>
+		</li>
+		{/if}
+	</ul>
+</div>
+<script>
+	$('#scanqrcode').click(function(){
+		wx.ready(function(){
+			wx.scanQRCode({
+				needResult: 0, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果,
+				scanType: ["qrCode","barCode"], // 可以指定扫二维码还是一维码,默认二者都有
+				success: function (res) {
+					var result = res.resultStr; // 当needResult 为 1 时,扫码返回的结果
+				}
+			});
+		});
+	});
+</script>
+{template 'common/footer'}

+ 46 - 0
framework/builtin/paycenter/template/mobile/login.html

xqd
@@ -0,0 +1,46 @@
+{php define(MUI, true);}
+{template 'common/header'}
+<header class="mui-bar mui-bar-nav">
+	<h1 class="mui-title">登录</h1>
+</header>
+<div class="mui-content paycenter-login" id="login-form">
+	<div class="mui-input-group">
+		<div class="mui-input-row">
+			<label>账号</label>
+			<input type="text" name="username" value="" placeholder="请输入登录账号"/>
+		</div>
+		<div class="mui-input-row">
+			<label>密码</label>
+			<input type="password" name="password" value="" placeholder="请输入登录密码"/>
+		</div>
+	</div>
+	<div class="mui-content-padded">
+		<button class="mui-btn mui-btn-success mui-btn-block" id="login-submit" type="submit">登录</button>
+	</div>
+</div>
+<script>
+$(function(){
+	$('#login-submit').click(function(){
+		var username = $.trim($('#login-form :text[name="username"]').val());
+		if(!username) {
+			alert('账号不能为空');
+			return false;
+		}
+		var password = $.trim($('#login-form input[name="password"]').val());
+		if(!password) {
+			alert('密码不能为空');
+			return false;
+		}
+		$.post(location.href, {username: username, password: password}, function(data){
+			var result = $.parseJSON(data);
+			if(result.message.errno != 0) {
+				alert(result.message.message);
+			} else {
+				location.reload();
+			}
+			return false;
+		});
+	});
+});
+</script>
+{template 'common/footer'}

+ 28 - 0
framework/builtin/paycenter/template/mobile/more.html

xqd
@@ -0,0 +1,28 @@
+{php define(MUI, true);}
+{template 'common/header'}
+<header class="mui-bar mui-bar-nav">
+	<h1 class="mui-title">{$_W['user']['store_name']}</h1>
+</header>
+{template 'nav'}
+<div class="mui-content paycenter-more">
+	<ul class="mui-table-view mui-table-view-chevron">
+		<li class="mui-table-view-cell mui-media store-info">
+			<a class="mui-navigate-right" href="javascript:;">
+				<img class="mui-media-object mui-pull-left mui-img-rounded" src="./resource/images/avatar.png">
+				<div class="mui-media-body">
+					{$clerk_name}
+					<div class="tel">{$clerk_info['mobile']}</div>
+				</div>
+			</a>
+		</li>
+		<li class="mui-table-view-cell">
+			<a href="javascript:;" class="mui-navigate-right">
+				{$store_name}
+			</a>
+		</li>
+	</ul>
+	<div class="mui-content-padded">
+		<a href="{php echo $this->createMobileUrl('logout')}" class="mui-btn mui-btn-block mui-btn-danger mui-btn-outlined">退出登录</a>
+	</div>
+</div>
+{template 'common/footer'}

+ 30 - 0
framework/builtin/paycenter/template/mobile/nav.html

xqd
@@ -0,0 +1,30 @@
+<nav class="mui-bar mui-bar-footer mui-table">
+	<div class="mui-table-cell">
+		<a class="{if $_GPC['do'] == 'home'}mui-active{/if}" href="{php echo $this->createMobileUrl('home');}">
+			<span class="mui-icon-img"><img src="./resource/images/{if $_GPC['do'] == 'home'}icon-home-active.png{else}icon-home.png{/if}" alt="" /></span>
+			<span class="mui-block">首页</span>
+		</a>
+	</div>
+	{if $_W['account']['level'] == ACCOUNT_SERVICE_VERIFY}
+	<div class="mui-table-cell">
+		<a class="{if $_GPC['do'] == 'scanpay'}mui-active{/if}" href="{php echo $this->createMobileUrl('scanpay');}">
+			<span class="mui-icon-img"><img src="./resource/images/{if $_GPC['do'] == 'scanpay'}icon-money-active.png{else}icon-money.png{/if}" alt="" /></span>
+			<span class="mui-block">收款</span>
+		</a>
+	</div>
+	{/if}
+	{if $_W['user']['clerk_type'] == 2 || ($_W['user']['clerk_type'] == 3 && in_array('coupon_consume', $user_permission))}
+	<div class="mui-table-cell">
+		<a class="{if $_GPC['do'] == 'cardconsume'}mui-active{/if}" href="{php echo $this->createMobileUrl('cardconsume', array('op' => 'consume'));}">
+			<span class="mui-icon-img"><img src="./resource/images/{if $_GPC['do'] == 'cardconsume'}icon-cancel-active.png{else}icon-cancel.png{/if}" alt="" /></span>
+			<span class="mui-block">核销</span>
+		</a>
+	</div>
+	{/if}
+	<div class="mui-table-cell">
+		<a class="{if $_GPC['do'] == 'more'}mui-active{/if}" href="{php echo $this->createMobileUrl('more');}">
+			<span class="mui-icon-img"><img src="./resource/images/{if $_GPC['do'] == 'more'}icon-more-active.png{else}icon-more.png{/if}" alt="" /></span>
+			<span class="mui-block">更多</span>
+		</a>
+	</div>
+</nav>

+ 53 - 0
framework/builtin/paycenter/template/mobile/order.html

xqd
@@ -0,0 +1,53 @@
+{template 'common/header'}
+<style>
+	.wx-qr-pay{padding:10px; max-width:640px; margin:0 auto;}
+	.wx-qr-pay .avatar{text-align:center; margin:20px;}
+	.wx-qr-pay .avatar img{width:60px; height:60px;}
+	.wx-qr-pay .qr-pay h5{text-align:center; border-bottom:1px solid #ddd; padding-bottom:10px;}
+	.wx-qr-pay .qr-pay .qr-img{text-align:center;}
+	.wx-qr-pay .qr-pay .qr-img img{width:70%; margin-bottom:5px;}
+</style>
+<div class="wx-qr-pay">
+	<div class="avatar">
+		<img src="{$fans['headimgurl']}" alt="" class="img-circle"/>
+	</div>
+	<form action="{php echo $this->createMobileUrl('order')}" method="post" id="form1">
+		<div class="form-group">
+			<input type="text" placeholder="付款人姓名" class="form-control" value="{$fans['nickname']}" disabled/>
+		</div>
+		<div class="form-group">
+			<input type="text" name="fee" placeholder="输入您要付的金额(必填,最小值0.01)" class="form-control" value="{$order['fee']}"/>
+		</div>
+		<div class="form-group">
+			<input type="text" name="body" placeholder="输入收款理由(必填)" class="form-control" value="{$order['body']}"/>
+		</div>
+		<div class="form-group">
+			<input type="hidden" name="openid" value="{$fans['openid']}"/>
+			<input type="hidden" name="nickname" value="{$fans['nickname']}"/>
+			<input type="hidden" name="token"" value="{$_W['token']}"/>
+			{loop $payment $row}
+				<input type="submit" name="submit" class="btn btn-success btn-block" value="提交订单">
+			{/loop}
+		</div>
+	</form>
+</div>
+
+<script type="text/javascript">
+	$(function(){
+		$('#form1').submit(function(){
+			var body = $.trim($('#form1 :text[name="body"]').val());
+			if(!body) {
+				alert('付款理由不能为空');
+				return false;
+			}
+			var reg = /^(([1-9]{1}\d*)|([0]{1}))(\.(\d){1,2})?$/;
+			var fee = $.trim($('#form1 :text[name="fee"]').val());
+			if(!reg.test(fee)) {
+				alert('支付金额不能少于0.01元');
+				return false;
+			}
+			return true;
+		});
+	});
+</script>
+{template 'common/footer'}

+ 25 - 0
framework/builtin/paycenter/template/mobile/paydetail.html

xqd
@@ -0,0 +1,25 @@
+{php define(MUI, true);}
+{template 'common/header'}
+<header class="mui-bar mui-bar-nav">
+	<a class="mui-icon mui-icon-left-nav mui-pull-left"></a>
+	<h1 class="mui-title">账单详情</h1>
+</header>
+<div class="mui-content trading-detail">
+	<ul class="mui-table-view">
+		<li class="mui-table-view-cell">
+			<div class="mui-text-muted">交易成功</div>
+			<div class="account">-{$order['final_fee']}</div>
+			<div class="text-right">
+				<a href="{php echo url('mc/card/mycard')}">返回会员卡</a>
+			</div>
+		</li>
+		<li class="mui-table-view-cell mui-media">
+			<a href="javascript:;">
+				<img src="./resource/images/icon-pay.png" alt="" class="mui-media-object mui-pull-left mui-img-rounded"/>
+				<div class="mui-media-body company">{$store['business_name']}</div>
+			</a>
+		</li>
+	</ul>
+</div>
+
+{template 'common/footer'}

+ 215 - 0
framework/builtin/paycenter/template/mobile/scanpay.html

xqd
@@ -0,0 +1,215 @@
+{php define(MUI, true);}
+{template 'common/header'}
+<header class="mui-bar mui-bar-nav">
+	<h1 class="mui-title">{$_W['user']['store_name']}</h1>
+</header>
+{template 'nav'}
+{if $op == 'index'}
+<header class="mui-bar mui-bar-nav">
+	<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
+	<button class="mui-btn mui-btn-link mui-btn-nav mui-pull-right">
+		<a href="{php echo $this->createMobileUrl('scanpay',array('op' => 'list'))}">收款记录</a>
+	</button>
+	<h1 class="mui-title">扫码收款</h1>
+</header>
+<div class="mui-content scan-pay">
+	<div class="mui-text-center mui-pa10 qrcode">
+		<div class="qrcode-block" data-url="{php echo murl('entry', array('m' => 'paycenter', 'do' => 'selfpay', 'clerk_id' => $_W['user']['clerk_id']), true, true);}" style="margin-top:20px"></div>
+		<div class="mui-card-block">
+			<div class="mui-text-muted">未设置优惠 <span class="problem">?</span></div>
+			<div class="scan">让顾客扫一扫,向我付款</div>
+		</div>
+	</div>
+	<div class="or mui-text-muted mui-text-center">或者</div>
+	<form action="{php echo $this->createMobileUrl('scanpay', array('op' => 'post'));}" method="post" id="pay-form">
+		<div class="mui-pa10 mui-bg-white">
+			<h5 class="mui-desc-title">设置收款金额</h5>
+			<div class="mui-input-row"><input type="text" value="" name="fee" placeholder="输入金额"/></div>
+			<div style="display:none">
+				<div class="mui-input-row"><input type="text" value="" name="body" placeholder="添加收款理由"/></div>
+				<div class="mui-text-right mui-text-success mui-mb10 hide-body">收起</div>
+			</div>
+			<div class="mui-text-right mui-text-success mui-mb10 add-body">添加收款理由</div>
+			<button class="mui-btn mui-btn-success mui-btn-block">发起收款</button>
+			<input type="hidden" name="token" value="{$_W['token']}"/>
+			<input type="hidden" name="submit" value="{$_W['token']}"/>
+		</div>
+	</form>
+</div>
+{/if}
+
+{if $op == 'qrcode'}
+<header class="mui-bar mui-bar-nav">
+	<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
+	<button class="mui-btn mui-btn-link mui-btn-nav mui-pull-right">
+		<a href="{php echo $this->createMobileUrl('scanpay',array('op' => 'list'))}">收款记录</a>
+	</button>
+	<h1 class="mui-title">扫码收款</h1>
+</header>
+<div class="mui-content scan-pay">
+	<div class="mui-content-padded mui-text-center qrcode">
+		<div class="qrcode-block" data-url="{php echo murl('entry', array('m' => 'paycenter', 'do' => 'pay', 'id' => $id), true, true);}" style="margin-top:20px"></div>
+		<div class="mui-card-block">
+			<div class="mui-text-muted">¥{$order['fee']}</div>
+			<div class="scan">让顾客扫一扫,向我付款</div>
+		</div>
+	</div>
+</div>
+{/if}
+
+{if $op == 'list'} 
+<header class="mui-bar mui-bar-nav">
+	<a class="mui-icon mui-action-back mui-icon-left-nav mui-pull-left"></a>
+	<a class="mui-btn mui-btn-link mui-btn-nav mui-pull-right" href="#check-date">
+		筛选
+	</a>
+	<h1 class="mui-title">账单</h1>
+</header>
+<div class="mui-content trading-record">
+	<ul class="mui-table-view">
+		{if empty($orders)}
+			<h1 class="mui-title">暂无记录</h1>
+		{else}
+		{loop $orders $order}
+			<li class="mui-table-view-cell">
+				<a href="{php echo $this->createMobileUrl('scanpay',array('op' => 'detail', 'id' => $order['id']))}">
+					<div class="mui-row">
+						<div class="mui-col-xs-4 mui-text-muted">
+							<span class="mui-block">{php echo date('Y-m-d', $order['paytime'])}</span>
+							<span class="mui-block">{php echo date("H:i", $order['paytime'])}</span>
+						</div>
+						<div class="mui-col-xs-3 mui-text-center">
+						<img src="./resource/images/icon-pay.png" alt="" class="mui-img-circle"/>
+						</div>
+						<div class="mui-col-xs-5">
+							<div><span class="mui-big">+{$order['final_fee']} </span></div>
+							<div class="mui-ellipsis">{if !empty($order['body'])}{$order['body']}{else}{暂无}{/if}</div>
+						</div>
+					</div>
+				</a>
+			</li>
+		{/loop}
+		{/if}
+	</ul>
+	<div id="check-date" class="mui-popover mui-popover-top">
+		<ul class="mui-table-view">
+			<li class="mui-table-view-cell">
+				<a href="{php echo $this->createMobileUrl('scanpay',array('op' => 'list', 'period' =>'1'))}">查看全部</a>
+			</li>
+			<li class="mui-table-view-cell">
+				<a href="{php echo $this->createMobileUrl('scanpay',array('op' => 'list', 'period' => '0'))}">{php echo date('Y.m.d',time());}</a>
+			</li>
+			<li class="mui-table-view-cell">
+				<a href="{php echo $this->createMobileUrl('scanpay',array('op' => 'list', 'period' => '-1'))}">{php echo date('Y.m.d',strtotime('-1day'));}</a>
+			</li>
+			<li class="mui-table-view-cell">
+				<a href="{php echo $this->createMobileUrl('scanpay',array('op' => 'list', 'period' => '-2'))}">{php echo date('Y.m.d',strtotime('-2day'));}</a>
+			</li>
+		</ul>
+	</div>
+</div>
+{/if}
+
+{if $op == 'detail'}
+<header class="mui-bar mui-bar-nav">
+	<a class="mui-icon mui-action-back mui-icon-left-nav mui-pull-left"></a>
+	<h1 class="mui-title">账单详情</h1>
+</header>
+<div class="mui-content trading-detail">
+	<ul class="mui-table-view">
+		<li class="mui-table-view-cell">
+			<div class="mui-text-muted">交易成功</div>
+			<div class="account">+{$order['final_fee']}</div>
+		</li>
+		<li class="mui-table-view-cell mui-media">
+			<a href="#">
+				<img src="./resource/images/icon-pay.png" alt="" class="mui-media-object mui-pull-left mui-img-rounded"/>
+				<div class="mui-media-body company">{$store_info['business_name']}</div>
+			</a>
+		</li>
+	</ul>
+	<ul class="mui-table-view">
+		<li class="mui-table-view-cell">
+			<label>订单详情</label>
+		</li>
+		<li class="mui-table-view-cell">
+			<label>付款说明</label>
+			<span class="mui-text-muted mui-ml15">{$order['body']}</span>
+		</li>
+		<li class="mui-table-view-cell">
+			<label>支付方式</label>
+			<span class="mui-text-muted mui-ml15">{$types[$order['type']]}-{$trade_types[$order['trade_type']]}</span>
+		</li>
+		<li class="mui-table-view-cell">
+			<label>支付者</label>
+			<span class="mui-text-muted mui-ml15">{if !empty($order['nickname'])}{$order['nickname']}{else}未知{/if}</span>
+		</li>
+		<li class="mui-table-view-cell">
+			<label>创建时间</label>
+			<span class="mui-text-muted mui-ml15">{php echo date('Y-m-d H:i:s', $order['createtime'])}</span>
+		</li>
+	</ul>
+	<ul class="mui-table-view">
+		<li class="mui-table-view-cell">
+			<label>支付详情</label>
+		</li>
+		<li class="mui-table-view-cell">
+			<label>应付金额</label>
+			<span class="mui-text-muted mui-ml15">{$order['fee']}</span>
+		</li>
+		<li class="mui-table-view-cell">
+			<label>实付金额</label>
+			<span class="mui-text-muted mui-ml15">{$order['final_fee']}</span>
+		</li>
+		<li class="mui-table-view-cell">
+			<label>积分抵现</label>
+			<span class="mui-text-muted mui-ml15">{$order['credit1_fee']}</span>
+		</li>
+		<li class="mui-table-view-cell">
+			<label>余额支付</label>
+			<span class="mui-text-muted mui-ml15">{$order['credit2']}</span>
+		</li>
+		<li class="mui-table-view-cell">
+			<label>线上支付</label>
+			<span class="mui-text-muted mui-ml15">{$order['cash']}</span>
+		</li>
+		<li class="mui-table-view-cell">
+			<label>支付时间</label>
+			<span class="mui-text-muted mui-ml15">{php echo date('Y-m-d H:i:s', $order['paytime'])}</span>
+		</li>
+	</ul>
+</div>
+{/if}
+
+<script>
+require(['jquery.qrcode'], function(){
+	$('#pay-form').submit(function(){
+		var fee = $.trim($('#pay-form :text[name="fee"]').val());
+		if(!fee) {
+			alert('收款金额应大于0');
+			return false;
+		}
+		return true;
+	});
+
+	$('.add-body').click(function(){
+		$(this).prev().show();
+		$(this).hide();
+	});
+
+	$('.hide-body').click(function(){
+		$(this).parent().hide();
+		$('.add-body').show();
+	});
+
+	var url = $('.qrcode-block').data('url');
+	$('.qrcode-block').html('').qrcode({
+		render: 'canvas',
+		width: 150,
+		height: 150,
+		text: url
+	});
+
+});
+</script>
+{template 'common/footer'}

+ 43 - 0
framework/builtin/paycenter/template/mobile/selfpay.html

xqd
@@ -0,0 +1,43 @@
+{php define(MUI, true);}
+{template 'common/header'}
+<header class="mui-bar mui-bar-nav">
+	<h1 class="mui-title">{$_W['user']['store_name']}</h1>
+</header>
+{template 'nav'}
+<header class="mui-bar mui-bar-nav">
+	<h1 class="mui-title">自助付款</h1>
+</header>
+<div class="mui-content self-help-pay">
+	<div class="mui-banner mui-text-center">
+		<img src="{$fans['avatar']}" alt="" class="mui-logo mui-img-circle"/>
+	</div>
+	<form action="" method="post">
+		<input type="hidden" name="openid" value="{$fans['openid']}"/>
+		<input type="hidden" name="nickname" value="{$fans['nickname']}"/>
+		<input type="hidden" name="token" value="{$_W['token']}"/>
+		<input type="hidden" name="submit" value="{$_W['token']}"/>
+		<div class="mui-card">
+			<div class="mui-card-block">
+				<div class="mui-card-title">金额(元)</div>
+				<textarea name="fee" rows="3" class="mui-border0" placeholder="¥"></textarea>
+			</div>
+		</div>
+		<div class="mui-content-padded">
+			<button class="mui-btn mui-btn-success mui-btn-block">立即支付</button>
+			<div class="mui-text-muted mui-text-center">支付完成后,如需退款请及时联系卖家</div>
+		</div>
+	</form>
+</div>
+<script>
+	$(function(){
+		$('#pay-form').submit(function(){
+			var fee = $.trim($('#pay-form :text[name="fee"]').val());
+			if(!fee) {
+				alert('付款金额应大于0');
+				return false;
+			}
+			return true;
+		});
+	});
+</script>
+{template 'common/footer'}

+ 357 - 0
framework/builtin/recharge/site.php

xqd
@@ -0,0 +1,357 @@
+<?php
+/**
+ * [WeEngine System] Copyright (c) 2014 WE7.CC
+ * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
+ */
+defined('IN_IA') or exit('Access Denied');
+
+class RechargeModuleSite extends WeModuleSite {
+	public function doMobilePay() {
+		global $_W, $_GPC;
+		checkauth();
+		$type = !empty($_GPC['type']) ? safe_gpc_string($_GPC['type']) : 'credit';
+		if ('credit' == $type) {
+			if (checksubmit()) {
+				$fee = floatval($_GPC['fee']);
+				$backtype = safe_gpc_string($_GPC['backtype']);
+				$back = floatval($_GPC['back']);
+				if (empty($fee) || $fee <= 0) {
+					message('请选择充值金额', referer(), 'error');
+				}
+				$chargerecord = array(
+					'uid' => $_W['member']['uid'],
+					'openid' => $_W['openid'],
+					'uniacid' => $_W['uniacid'],
+					'tid' => date('YmdHi') . random(8, 1),
+					'fee' => $fee,
+					'type' => 'credit',
+					'tag' => $back,
+					'backtype' => $backtype,
+					'status' => 0,
+					'createtime' => TIMESTAMP,
+				);
+				if (!table('mc_credits_recharge')->fill($chargerecord)->save()) {
+					message('创建充值订单失败,请重试!', url('entry', array('m' => 'recharge', 'do' => 'pay')), 'error');
+				}
+				$params = array(
+					'tid' => $chargerecord['tid'],
+					'ordersn' => $chargerecord['tid'],
+					'title' => '会员余额充值',
+					'fee' => $chargerecord['fee'],
+					'user' => $_W['member']['uid'],
+				);
+				$mine = array();
+				if (empty($backtype)) {
+					$condition = $fee;
+					$mine = array(
+						'name' => "充{$condition}送{$back}元",
+						'value' => $fee,
+					);
+				} elseif ('1' == $backtype) {
+					$condition = $fee;
+					$mine = array(
+						'name' => "充{$condition}送{$back}积分",
+						'value' => $fee,
+					);
+				} elseif ('2' == $backtype) {
+					$condition = $fee;
+				}
+				$this->pay($params, $mine);
+				exit();
+			}
+			$member = mc_fetch($_W['member']['uid']);
+			$name = $member['mobile'];
+			if (empty($name)) {
+				$name = $member['realname'];
+			}
+			if (empty($name)) {
+				$name = $member['uid'];
+			}
+			include $this->template('recharge');
+		} else {
+			$fee = floatval($_GPC['fee']);
+			if (!$fee) {
+				message('充值金额不能为0', referer(), 'error');
+			}
+			if ($fee <= 0) {
+				message('请输入充值的金额', referer(), 'error');
+			}
+			$setting = table('mc_card')->getByStatus(1, $_W['uniacid']);
+			if (empty($setting)) {
+				message('会员卡未开启,请联系商家', referer(), 'error');
+			}
+			if ('card_nums' == $type) {
+				if (!$setting['nums_status']) {
+					message("会员卡未开启{$setting['nums_text']}充值,请联系商家", referer(), 'error');
+				}
+				$setting['nums'] = iunserializer($setting['nums']);
+				$num_keys = array_keys($setting['nums']);
+				if (!in_array($fee, $num_keys)) {
+					message('充值金额错误,请联系商家', referer(), 'error');
+				}
+				foreach ($setting['nums'] as $key => $val) {
+					if ($fee == $val['recharge']) {
+						$num_back = $val['num'];
+					}
+				}
+				$mine = array(
+					'name' => "充{$fee}送{$num_back}次",
+					'value' => "送{$num_back}次",
+				);
+				$tag = $num_back;
+			}
+			if ('card_times' == $type) {
+				if (!$setting['times_status']) {
+					message("会员卡未开启{$setting['times_text']}充值,请联系商家", referer(), 'error');
+				}
+
+				$setting['times'] = iunserializer($setting['times']);
+				$time_keys = array_keys($setting['times']);
+				if (!in_array($fee, $time_keys)) {
+					message('充值金额错误,请联系商家', referer(), 'error');
+				}
+				foreach ($setting['times'] as $key => $val) {
+					if ($fee == $val['recharge']) {
+						$time_back = $val['time'];
+					}
+				}
+				$member_card = table('mc_card_members')->getByUid($_W['member']['uid'], $_W['uniacid']);
+				if ($member_card['endtime'] > TIMESTAMP) {
+					$endtime = $member_card['endtime'] + time_back * 86400;
+				} else {
+					$endtime = strtotime($time_back . 'days');
+				}
+				$mine = array(
+					'name' => "充{$fee}送{$time_back}天",
+					'value' => date('Y-m-d', $endtime) . '到期',
+				);
+				$tag = $time_back;
+			}
+			$chargerecord = table('mc_credits_recharge')
+				->where(array(
+					'uniacid' => $_W['uniacid'],
+					'uid' => $_W['member']['uid'],
+					'fee' => $fee,
+					'type' => $type,
+					'status' => 0,
+					'tag' => $tag,
+				))
+				->get();
+
+			if (empty($chargerecord)) {
+				$chargerecord = array(
+					'uid' => $_W['member']['uid'],
+					'openid' => $_W['openid'],
+					'uniacid' => $_W['uniacid'],
+					'tid' => date('YmdHi') . random(8, 1),
+					'fee' => $fee,
+					'type' => $type,
+					'tag' => $tag,
+					'status' => 0,
+					'createtime' => TIMESTAMP,
+				);
+				if (!table('mc_credits_recharge')->fill($chargerecord)->save()) {
+					message('创建充值订单失败,请重试!', url('mc/card/mycard'), 'error');
+				}
+			}
+			$types = array(
+				'card_nums' => $setting['nums_text'],
+				'card_times' => $setting['times_text'],
+			);
+			$params = array(
+				'tid' => $chargerecord['tid'],
+				'ordersn' => $chargerecord['tid'],
+				'title' => "会员卡{$types[$type]}充值",
+				'fee' => $chargerecord['fee'],
+				'user' => $_W['member']['uid'],
+			);
+			$this->pay($params, $mine);
+			exit();
+		}
+	}
+
+	
+	public function payResult($params) {
+		global $_W;
+		load()->model('mc');
+		load()->model('card');
+		$order = table('mc_credits_recharge')->where(array('tid' => $params['tid']))->get();
+		if ('success' == $params['result'] && 'notify' == $params['from']) {
+			$fee = $params['fee'];
+			$total_fee = $fee;
+			$data = array('status' => 'success' == $params['result'] ? 1 : -1);
+			
+			if ('wechat' == $params['type']) {
+				$data['transid'] = $params['tag']['transaction_id'];
+				$params['user'] = mc_openid2uid($params['user']);
+			}
+			table('mc_credits_recharge')->where(array('tid' => $params['tid']))->fill($data)->save();
+			$paydata = array('wechat' => '微信', 'alipay' => '支付宝', 'baifubao' => '百付宝', 'unionpay' => '银联');
+			
+			if (empty($order['type']) || 'credit' == $order['type']) {
+				$setting = uni_setting($_W['uniacid'], array('creditbehaviors', 'recharge'));
+				$credit = $setting['creditbehaviors']['currency'];
+				$we7_coupon_info = module_fetch('we7_coupon');
+				if (!empty($we7_coupon_info)) {
+					$recharge_settings = card_params_setting('cardRecharge');
+					$recharge_params = $recharge_settings['params'];
+				} else {
+					$recharge_params = array(
+						'recharge_type' => '',
+						'recharges' => ''
+					);
+				}
+				if (empty($credit)) {
+					message('站点积分行为参数配置错误,请联系服务商', '', 'error');
+				} else {
+					if ('1' == $recharge_params['recharge_type']) {
+						$recharges = $recharge_params['recharges'];
+					}
+					if ('2' == $order['backtype']) {
+						$total_fee = $fee;
+					} else {
+						foreach ($recharges as $key => $recharge) {
+							if ($recharge['backtype'] == $order['backtype'] && $recharge['condition'] == $order['fee']) {
+								if ('1' == $order['backtype']) {
+									$total_fee = $fee;
+									$add_credit = $recharge['back'];
+								} else {
+									$total_fee = $fee + $recharge['back'];
+								}
+							}
+						}
+					}
+					if ('1' == $order['backtype']) {
+						$add_str = ",充值成功,返积分{$add_credit}分,本次操作共增加余额{$total_fee}元,积分{$add_credit}分";
+						$remark = '用户通过' . $paydata[$params['type']] . '充值' . $fee . $add_str;
+						$record[] = $params['user'];
+						$record[] = $remark;
+						mc_credit_update($order['uid'], 'credit1', $add_credit, $record);
+						mc_credit_update($order['uid'], 'credit2', $total_fee, $record);
+						mc_notice_recharge($order['openid'], $order['uid'], $total_fee, '', $remark);
+					} else {
+						$add_str = ",充值成功,本次操作共增加余额{$total_fee}元";
+						$remark = '用户通过' . $paydata[$params['type']] . '充值' . $fee . $add_str;
+						$record[] = $params['user'];
+						$record[] = $remark;
+						mc_credit_update($order['uid'], 'credit2', $total_fee, $record);
+						mc_notice_recharge($order['openid'], $order['uid'], $total_fee, '', $remark);
+					}
+				}
+			}
+
+			
+			if ('card_nums' == $order['type']) {
+				$member_card = table('mc_card_members')->getByUid($order['uid'], $_W['uniacid']);
+				$total_num = $member_card['nums'] + $order['tag'];
+				table('mc_card_members')
+					->where(array(
+						'uniacid' => $order['uniacid'],
+						'uid' => $order['uid']
+					))
+					->fill( array('nums' => $total_num))
+					->save();
+				
+				$log = array(
+					'uniacid' => $order['uniacid'],
+					'uid' => $order['uid'],
+					'type' => 'nums',
+					'fee' => $params['fee'],
+					'model' => '1',
+					'tag' => $order['tag'], 
+					'note' => date('Y-m-d H:i') . "通过{$paydata[$params['type']]}充值{$params['fee']}元,返{$order['tag']}次,总共剩余{$total_num}次",
+					'addtime' => TIMESTAMP,
+				);
+				table('mc_card_record')->fill($log)->save();
+				$type = table('mc_card')->where(array('uniacid' => $order['uniacid']))->getcolumn('nums_text');
+				$total_num = $member_card['nums'] + $order['tag'];
+				mc_notice_nums_plus($order['openid'], $type, $order['tag'], $total_num);
+			}
+
+			
+			if ('card_times' == $order['type']) {
+				$member_card = table('mc_card_members')->getByUid($order['uid'], $_W['uniacid']);
+				if ($member_card['endtime'] > TIMESTAMP) {
+					$endtime = $member_card['endtime'] + $order['tag'] * 86400;
+				} else {
+					$endtime = strtotime($order['tag'] . 'days');
+				}
+				table('mc_card_members')
+					->where(array(
+						'uniacid' => $order['uniacid'],
+						'uid' => $order['uid']
+					))
+					->fill(array('endtime' => $endtime))
+					->save();
+				$log = array(
+					'uniacid' => $order['uniacid'],
+					'uid' => $order['uid'],
+					'type' => 'times',
+					'model' => '1',
+					'fee' => $params['fee'],
+					'tag' => $order['tag'], 
+					'note' => date('Y-m-d H:i') . "通过{$paydata[$params['type']]}充值{$params['fee']}元,返{$order['tag']}天,充值后到期时间:" . date('Y-m-d', $endtime),
+					'addtime' => TIMESTAMP,
+				);
+				table('mc_card_record')->fill($log)->save();
+				$type = table('mc_card')->where(array('uniacid' => $order['uniacid']))->getcolumn('times_text');
+				$endtime = date('Y-m-d', $endtime);
+				mc_notice_times_plus($order['openid'], $member_card['cardsn'], $type, $fee, $order['tag'], $endtime);
+			}
+		}
+		if ('credit' == $order['type'] || '' == $order['type']) {
+			$url = murl('mc/home');
+		} else {
+			$url = murl('mc/card/mycard');
+		}
+		
+		if ('return' == $params['from']) {
+			if ('success' == $params['result']) {
+				message('支付成功!', $_W['siteroot'] . 'app/' . $url, 'success');
+			} else {
+				message('支付失败!', $_W['siteroot'] . 'app/' . $url, 'error');
+			}
+		}
+	}
+
+	protected function pay($params = array(), $mine = array()) {
+		global $_W;
+		$params['module'] = $this->module['name'];
+		$log = table('core_paylog')
+			->where(array(
+				'uniacid' => $_W['uniacid'],
+				'module' => $params['module'],
+				'tid' => $params['tid'],
+			))
+			->get();
+		if (!empty($log) && '1' == $log['status']) {
+			itoast('这个订单已经支付成功, 不需要重复支付.', '', 'info');
+		}
+		$setting = uni_setting($_W['uniacid'], array('payment', 'creditbehaviors'));
+		if (!is_array($setting['payment'])) {
+			itoast('没有有效的支付方式, 请联系网站管理员.', '', 'error');
+		}
+		if (empty($log)) {
+			$log = array(
+				'uniacid' => $_W['uniacid'],
+				'acid' => $_W['acid'],
+				'openid' => $_W['member']['uid'],
+				'module' => $this->module['name'], 
+				'tid' => $params['tid'],
+				'fee' => $params['fee'],
+				'card_fee' => $params['fee'],
+				'status' => '0',
+				'is_usecard' => '0',
+			);
+			table('core_paylog')->fill($log)->save();
+		}
+		$pay = $setting['payment'];
+		foreach ($pay as &$value) {
+			$value['switch'] = $value['recharge_switch'];
+		}
+		unset($value);
+		$pay['credit']['switch'] = false;
+		$pay['delivery']['switch'] = false;
+		include $this->template('common/paycenter');
+	}
+}

Some files were not shown because too many files changed in this diff