|
|
@@ -2,18 +2,22 @@
|
|
|
|
|
|
namespace app\extra\basic;
|
|
|
|
|
|
-use app\extra\douyin\Client;
|
|
|
use app\extra\tools\CodeExtend;
|
|
|
-use app\model\saas\SaasOrderLife;
|
|
|
-use app\model\saas\SaasOrderLog;
|
|
|
-use app\model\saas\SaasStore;
|
|
|
use app\model\system\SystemUser;
|
|
|
-use Overtrue\EasySms\Strategies\OrderStrategy;
|
|
|
+use think\contract\Arrayable;
|
|
|
use think\Validate;
|
|
|
|
|
|
class Base
|
|
|
{
|
|
|
|
|
|
+
|
|
|
+ const DEFAULT_SUCCESS_MESSAGE = 'success';
|
|
|
+ const DEFAULT_FAIL_MESSAGE = 'fail';
|
|
|
+
|
|
|
+ const DEFAULT_SUCCESS_CODE = 200;
|
|
|
+ const DEFAULT_FAIL_CODE = 400;
|
|
|
+
|
|
|
+
|
|
|
protected function getParent(array $data)
|
|
|
{
|
|
|
if ($data['parent_id'] > 0) {
|
|
|
@@ -37,63 +41,6 @@ class Base
|
|
|
return ["appid" => sConf('dy.appid'),'secret' => sConf('dy.secret')];
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- /**
|
|
|
- * 同步订单-实时
|
|
|
- * @param string $account
|
|
|
- * @param string $openId
|
|
|
- */
|
|
|
- protected function asyncDyOrder(string $account = "",string $openId = "",string $orderId = "")
|
|
|
- {
|
|
|
- // 同步已经下单的订单
|
|
|
- if (!empty($account)) {
|
|
|
- if (!empty($orderId)) {
|
|
|
- $order = (new SaasOrderLife)->where("order_id",$orderId)->findOrEmpty();
|
|
|
- if (!$order->isEmpty()) return [];
|
|
|
- }
|
|
|
- $resp = (new Client)->config($this->getDyConfig())->token()->queryOrder($account,$openId);
|
|
|
- $store = (new SaasStore)->where("store_id",$account)->findOrEmpty();
|
|
|
- if (empty($resp['data']['orders'])) return [];
|
|
|
- $lifeOrder = $resp['data']['orders'][0];
|
|
|
- $orderData = $orderLog = [];
|
|
|
- foreach ($lifeOrder['certificates'] as $key=>$val) {
|
|
|
- $orderEx = (new SaasOrderLife)->where("order_id",$lifeOrder['order_id'])->where("certificate_id",$val['certificate_id'])->findOrEmpty();
|
|
|
- if ($orderEx->isEmpty()) {
|
|
|
- $orderData[$key] = [
|
|
|
- "open_id" => $openId,
|
|
|
- "agent_id" => $store['agent_id']??'',
|
|
|
- "store_id" => $store['store_id']??'',
|
|
|
- "order_id" => $lifeOrder['order_id'],
|
|
|
- "pay_amount" => $val['amount']['pay_amount'],
|
|
|
- "order_amount" => $val['amount']['original_amount'],
|
|
|
- "expire_at" => date("Y-m-d H:i:s",$val['expire_time']),
|
|
|
- "out_id" => $val['sku_info']['sku_id'],
|
|
|
- "product_name" => $val['sku_info']['title'],
|
|
|
- "groupon_type" => $val['sku_info']['groupon_type'],
|
|
|
- "certificate_id" => $val['certificate_id']??'',
|
|
|
- "status" => 1,
|
|
|
- "pay_at" => getDateFull(),
|
|
|
- "start_time" => date("Y-m-d H:i:s",$val['start_time']),
|
|
|
- ];
|
|
|
- } else {
|
|
|
- $orderEx->save([
|
|
|
- "open_id" => $openId,
|
|
|
- "expire_at" => date("Y-m-d H:i:s",$val['expire_time']),
|
|
|
- "out_id" => $val['sku_info']['sku_id'],
|
|
|
- "product_name" => $val['sku_info']['title'],
|
|
|
- "groupon_type" => $val['sku_info']['groupon_type'],
|
|
|
- "certificate_id" => $val['certificate_id']??'',
|
|
|
- "start_time" => date("Y-m-d H:i:s",$val['start_time']),
|
|
|
- ]);
|
|
|
- }
|
|
|
- }
|
|
|
- if (!empty($orderData)) {
|
|
|
- (new SaasOrderLife)->insertAll(array_values($orderData));
|
|
|
- }
|
|
|
- return [];
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 写入新用户
|
|
|
* @param array $param
|
|
|
@@ -172,6 +119,75 @@ class Base
|
|
|
}
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ * @param $data
|
|
|
+ * @return array|string|null
|
|
|
+ */
|
|
|
+ private function parseData($data)
|
|
|
+ {
|
|
|
+ if ($data instanceof Arrayable)
|
|
|
+ return $data->toArray();
|
|
|
+ else
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param string|array|Arrayable $message
|
|
|
+ * @param array|Arrayable|null $data
|
|
|
+ * @return Json
|
|
|
+ */
|
|
|
+ public function success($message = self::DEFAULT_SUCCESS_MESSAGE, $data = null)
|
|
|
+ {
|
|
|
+ $message = $this->parseData($message);
|
|
|
+ if (is_array($message)) {
|
|
|
+ $data = $message;
|
|
|
+ $message = self::DEFAULT_SUCCESS_MESSAGE;
|
|
|
+ } else {
|
|
|
+ $data = $this->parseData($data);
|
|
|
+ }
|
|
|
+ return $this->make(self::DEFAULT_SUCCESS_CODE, $message, $data);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param int $status
|
|
|
+ * @param string $message
|
|
|
+ * @param array|Arrayable|null $data
|
|
|
+ */
|
|
|
+ public function make(int $status, string $message, $data = null)
|
|
|
+ {
|
|
|
+ $content = compact('status', 'message');
|
|
|
+ if (!is_null($data))
|
|
|
+ $content['data'] = $this->parseData($data);
|
|
|
+ return json($content);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function encode($message = self::DEFAULT_SUCCESS_MESSAGE, $data = null)
|
|
|
+ {
|
|
|
+ $message = $this->parseData($message);
|
|
|
+ if (is_array($message)) {
|
|
|
+ $data = $message;
|
|
|
+ $message = self::DEFAULT_SUCCESS_MESSAGE;
|
|
|
+ } else {
|
|
|
+ $data = $this->parseData($data);
|
|
|
+ }
|
|
|
+ $status = self::DEFAULT_SUCCESS_CODE;
|
|
|
+ $encode = true;
|
|
|
+ $content = compact('status','encode', 'message');
|
|
|
+ if (is_null($data) || env('APP_DEBUG', false))
|
|
|
+ return $this->success($message, $data['data'] ?? $data);
|
|
|
+ if (!is_array($data) || !isset($data['data'])) {
|
|
|
+ $res['data'] = $data;
|
|
|
+ } else {
|
|
|
+ $res = $data;
|
|
|
+ }
|
|
|
+ $res['status'] = $status;
|
|
|
+ $res['message'] = $message;
|
|
|
+ $content['data'] = base64_encode(gzdeflate(json_encode($res,JSON_UNESCAPED_UNICODE),9));
|
|
|
+ return json($content);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 菜单信息格式化
|
|
|
* @param array $menus
|