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() ]; } } }