| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\admin\models;
- use app\models\Admin;
- use app\models\AggregateSaasQrcode as AggregateQrcode;
- use app\models\Option;
- use app\models\SaasUser;
- use app\models\Salesman;
- use app\models\Store;
- use app\models\StoreAliMini;
- use app\models\StoreMini;
- use app\models\WechatConfig;
- use app\utils\QrCode;
- use EasyWeChat\Factory;
- use yii\base\Model;
- use AopClient;
- use app\models\SaasCategory;
- include_once \Yii::$app->basePath . "/utils/Alipay/alipaySdk/aop/AopClient.php";;
- class AggregateSaasQrcodeForm extends Model
- {
- public $id;
- public $store_id;
- public $param_url;
- public $admin_id;
- public $is_use;
- public $mini_url;
- public $create_time;
- public $number;
- public $name;
- public $salesman_name;
- public $status;
- public $salesman_id;
- public $ids;
- public function rules()
- {
- return [
- [["id", "store_id", "mini_id", "admin_id", "salesman_id", "is_use", "number", 'salesman_id'], 'integer'],
- [["param_url", "qrcode_url", "mini_url", "create_time",], 'string'],
- [['ids'], 'array']
- ];
- }
- public function createdUrl()
- {
- $num = 0;
- $id = [];
- foreach (range(1, $this->number) as $item) {
- $max_id = AggregateQrcode::find()->max('id');
- $qrcode = new AggregateQrcode();
- $qrcode->create_time = time();
- $qrcode->store_id = 0;
- $qrcode->mini_url = "/face-pay/face-pay/payOut";
- $res = $qrcode->save();
- if ($res) {
- $qrcode->param_url = \Yii::$app->request->hostInfo . '/web/face/saas/pay?id=' . ($qrcode->id);
- $res = $qrcode->save();
- if ($res) {
- array_push($id, $qrcode->id);
- $num++;
- }
- }
- }
- return [
- 'code' => 0,
- 'msg' => '已成功生成' . $num . '条链接',
- 'id' => $id
- ];
- }
- public function qrcodeList()
- {
- //业务员列表
- $query = Salesman::find()->alias('s')->leftJoin(['su' => SaasUser::tableName()], 's.saas_user_id = su.id')->where(['s.is_delete' => 0]);
- $Salesman = $query->select('s.id, su.name')->asArray()->all();
- //end
- //商城列表,排除已经绑定过聚合码的商城 start
- $store_ids = AggregateQrcode::find()->where(['and', ['<>', 'store_id', 0]])->select("store_id")->column();
- if (\Yii::$app->prod_is_dandianpu()) {
- $self_mini = Option::find()->where(['name' => 'self_mini', 'group' => 'store', 'value' => 1])->select("store_id")->column();
- $store_ids = array_merge($self_mini, $store_ids);
- $stores = Store::find()->where(['not in', 'id', $store_ids])->andWhere(['is_delete' => 0])->asArray()->select('id, name, salesman_id')->all();
- } else {
- $stores = Store::find()->where(['not in', 'id', $store_ids])->andWhere(['and', ['is_delete' => 0], ['<>', 'business_model', '1']])->asArray()->select('id, name, salesman_id')->all();
- }
- //end
- $query = AggregateQrcode::find()->alias('aq')->leftJoin(['s' => Store::tableName()], 'aq.store_id = s.id');
- $query->leftJoin(['sm' => Salesman::tableName()], 'aq.salesman_id = sm.id');
- $query->leftJoin(['su' => SaasUser::tableName()], 'sm.saas_user_id = su.id');
- $query->leftJoin(['a' => Admin::tableName()], 'aq.admin_id = a.id');
- $query->leftJoin(['c' => SaasCategory::tableName()], 's.category_id = c.id');
- if (!empty($this->name)) {
- $query->andWhere(['LIKE', 's.name', $this->name]);
- }
- if (!empty($this->salesman_name)) {
- $query->andWhere(['LIKE', 'sm.name', $this->salesman_name]);
- }
- switch ($this->status) {
- case 1:
- $query->andWhere(['shop_bind_time' => '']);
- break;
- case 2:
- $query->andWhere(['<>', 'shop_bind_time', '']);
- break;
- }
- $query = $query->select('s.name store_name, aq.id, aq.store_id, aq.admin_id, aq.salesman_id, aq.is_use, aq.shop_bind_time, su.name salesman_name, a.name admin_name, s.logo as store_logo, c.name as category_name')
- ->orderBy('id desc');
- $pagination = pagination_make($query);
- foreach ($pagination['list'] as &$item) {
- if (empty($item['shop_bind_time'])) {
- $item['status'] = 1;
- }
- if (!empty($item['shop_bind_time'])) {
- $item['status'] = 2;
- }
- $item['business_no'] = null;
- $wechatConfig = WechatConfig::find()->where(['store_id' => $item['store_id']])->select('mch_id')->one();
- if ($wechatConfig) {
- $item['business_no'] = $wechatConfig->mch_id;
- }
- }
- return [
- 'code' => 0,
- 'msg' => "获取成功",
- 'data' => $pagination['list'],
- 'store_list' => $stores,//商城列表
- 'salesman_list' => $Salesman,
- 'pageNo' => $pagination['pageNo'],
- 'totalCount' => $pagination['totalCount']
- ];
- }
- public function urlDel()
- {
- $t = \Yii::$app->db->beginTransaction();
- try {
- if (empty($this->ids)) {
- throw new \Exception("没有选择数据");
- }
- $res = AggregateQrcode::deleteAll(['id' => $this->ids]);
- if ($res) {
- $t->commit();
- return [
- 'code' => 0,
- 'msg' => "删除成功"
- ];
- } else {
- throw new \Exception("删除失败");
- }
- } catch (\Exception $e) {
- $t->rollBack();
- return [
- 'code' => 0,
- 'msg' => $e->getMessage()
- ];
- }
- }
- //绑定商城
- public function bindStore()
- {
- try {
- $ag = AggregateQrcode::findone($this->id);
- if (!empty($ag)) {
- //绑定商城
- if (!empty($this->store_id)) {
- $st_ag = AggregateQrcode::findone(['store_id' => $this->store_id]);
- if (!empty($st_ag)) {
- throw new \Exception("此商城已经被绑定");
- }
- if (!empty($ag->store_id)) {
- throw new \Exception("已经绑定过商城");
- }
- $store = Store::find()->where(['id' => $this->store_id])->select("id,salesman_id")->one();
- if (!empty($store->salesman_id)) {
- $Salesman = Salesman::findOne($store->salesman_id);
- $ag->salesman_id = $store->salesman_id;
- $ag->admin_id = $Salesman->admin_id;
- }
- $ag->store_id = $this->store_id;
- $ag->shop_bind_time = time();
- if (!$ag->save()) {
- throw new \Exception("商城绑定失败");
- }
- return [
- 'code' => 0,
- 'msg' => "绑定成功"
- ];
- }
- if (empty($ag->store_id)) {
- throw new \Exception("请先绑定商城");
- }
- } else {
- throw new \Exception("没有找到二维码信息");
- }
- } catch (\Exception $e) {
- return [
- 'code' => 1,
- 'msg' => $e->getMessage()
- ];
- }
- }
- //生成可使用的链接进行显示
- public function showQrcode()
- {
- try {
- $qrcode = AggregateQrcode::find()->where(['store_id' => 0, 'is_use' => 1])->andWhere(['and', ['<>', 'param_url', ''], ['<>', 'mini_url', '']])->select('id, mini_url, param_url')->one();
- if (empty($qrcode)) {
- $this->number = 1;
- $result = $this->createdUrl();
- $qrcode = AggregateQrcode::find()->where(['id' => $result['id']])->select('id, mini_url, param_url')->one();
- }
- $qrcode->mini_url = substr($qrcode->mini_url, 1, strlen($qrcode->mini_url));
- if (!empty($qrcode->param_url)) {
- $index = strpos($qrcode->param_url, '?');
- $qrcode->param_url = substr($qrcode->param_url, 0, $index);
- $index = strpos($qrcode->param_url, '//');
- $qrcode->param_url = substr($qrcode->param_url, ($index + 2));
- }
- return [
- 'code' => 0,
- 'msg' => "获取成功",
- 'data' => $qrcode
- ];
- } catch (\Exception $e) {
- return [
- 'code' => 1,
- 'msg' => $e->getMessage()
- ];
- }
- }
- }
|