IndexLogic.php 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. <?php
  2. namespace app\api\logic;
  3. use app\model\CommonModel;
  4. use app\model\SupplierModel;
  5. use app\model\DevelopmentModel;
  6. use think\Exception;
  7. use think\facade\Cache;
  8. use think\facade\Config;
  9. use think\facade\Db;
  10. use think\helper\Str;
  11. class IndexLogic
  12. {
  13. //刷新密钥
  14. public static function refreshSecret(array $param = [])
  15. {
  16. $supplier = SupplierModel::alias('a')
  17. ->field('a.id,a.code')
  18. ->join('wsm_supplier_contact b', 'b.code=a.code')
  19. ->where([
  20. 'a.name' => $param['supplierName'],
  21. 'a.legaler' => $param['legaler'],
  22. 'a.registercode' => $param['registercode'],
  23. 'b.contactor' => $param['contactor'],
  24. 'b.mobile' => $param['mobile'],
  25. 'a.is_del' => 0
  26. ])
  27. ->findOrEmpty()
  28. ->toArray();
  29. if (empty($supplier)) return json_show(CommonModel::$error_param, '相关供应商不存在');
  30. $clientID = $supplier['code'];//clientID,暂时取用供应商编码字段
  31. $clientSercert = Str::random(40, 5);//clientSercert,随机40个字符
  32. $data = array_merge($param, [
  33. 'supplierNo' => $supplier['code'],
  34. 'clientID' => $clientID,
  35. 'clientSecret' => $clientSercert,
  36. ]);
  37. $id = DevelopmentModel::where('supplierNo', $supplier['code'])
  38. ->value('id', 0);
  39. if ($id) $res = DevelopmentModel::where('id', $id)->save($data); //更新
  40. else {
  41. $res = DevelopmentModel::create($data);
  42. $id = $res->id;
  43. } //新增
  44. if ($res) {
  45. Cache::set(Config::get('redis_key.development_clientID') . $clientID, json_encode(array_merge(['id' => $id], $data), JSON_UNESCAPED_UNICODE), 30 * 24 * 3600);
  46. return json_show(CommonModel::$success, '刷新密钥成功', ['clientID' => $clientID, 'clientSecret' => $clientSercert]);
  47. } else return json_show(CommonModel::$error_default, '刷新密钥失败');;
  48. }
  49. //修改开发信息中的推送地址
  50. public static function updatePushUrl(array $param = [])
  51. {
  52. $res = DevelopmentModel::where('supplierNo', request()->development['supplierNo'])
  53. ->save(['push_url' => implode(',', $param['push_url'])]);
  54. return $res ? json_show(CommonModel::$success, '修改推送地址成功') : json_show(CommonModel::$error_default, '修改推送地址失败');
  55. }
  56. //获取推送记录
  57. public static function getPushLog(array $param = [])
  58. {
  59. $res = Db::name('push_log')
  60. ->where('supplierNo', request()->development['supplierNo']);
  61. if ($param['push_url'] != '') $res->whereLike('push_url', '%' . $param['push_url'] . '%');
  62. if ($param['type']) $res->where('type', $param['type']);
  63. if ($param['start'] != '') $res->where('addtime', '>=', $param['start']);
  64. if ($param['end'] != '') $res->where('addtime', '<=', $param['end']);
  65. $count = $res->count('id');
  66. $list = $res
  67. ->page($param['page'], $param['size'])
  68. ->order('id')
  69. ->select()
  70. ->toArray();
  71. return json_show(CommonModel::$success, '获取推送记录成功', ['count' => $count, 'list' => $list]);
  72. }
  73. //获取上线平台列表
  74. // public static function getPlatformList(string $keyword = '', int $page = 1, int $size = 15)
  75. // {
  76. //
  77. // $db = Db::connect('mysql_wsm')
  78. // ->name('platform')
  79. // ->where('is_del', 0);
  80. //
  81. // if ($keyword != '') $db->whereLike('platform_name', '%' . $keyword . '%');
  82. //
  83. // $count = $db->count('id');
  84. //
  85. // $list = $db
  86. // ->field('id platform_id,platform_code,platform_name,platform_type')
  87. // ->order('id')
  88. // ->page($page, $size)
  89. // ->select()
  90. // ->toArray();
  91. //
  92. // return json_show(0, '请求成功', ['count' => $count, 'list' => $list]);
  93. //
  94. // }
  95. //获取分类列表
  96. public static function getCatList(string $keyword = '', int $pid = 0)
  97. {
  98. $db = Db::connect('mysql_wsm')
  99. ->name('cat')
  100. ->where(['is_del' => 0, 'pid' => $pid]);
  101. if ($keyword != '') $db->whereLike('cat_name', '%' . $keyword . '%');
  102. $count = $db->count('id');
  103. $list = $db
  104. ->field('id cat_id,cat_name,level')
  105. ->order('id')
  106. ->select()
  107. ->toArray();
  108. return json_show(0, '请求成功', ['count' => $count, 'list' => $list]);
  109. }
  110. //获取品牌列表
  111. public static function getBrandList(string $keyword = '', int $page = 1, int $size = 15)
  112. {
  113. $db = Db::connect('mysql_wsm')
  114. ->name('brand')
  115. ->where('is_del', 0);
  116. if ($keyword != '') $db->whereLike('brand_name', '%' . $keyword . '%');
  117. $count = $db->count('id');
  118. $list = $db
  119. ->field('id brand_id,brand_name')
  120. ->order('id')
  121. ->page($page, $size)
  122. ->select()
  123. ->toArray();
  124. return json_show(0, '请求成功', ['count' => $count, 'list' => $list]);
  125. }
  126. //获取单位列表
  127. public static function getUnitList(string $keyword = '', int $page = 1, int $size = 15)
  128. {
  129. $db = Db::connect('mysql_wsm')
  130. ->name('unit')
  131. ->where('is_del', 0);
  132. if ($keyword != '') $db->whereLike('unit', '%' . $keyword . '%');
  133. $count = $db->count('id');
  134. $list = $db
  135. ->field('id unit_id,unit unit_name')
  136. ->order('id')
  137. ->page($page, $size)
  138. ->select()
  139. ->toArray();
  140. return json_show(0, '请求成功', ['count' => $count, 'list' => $list]);
  141. }
  142. //获取规格标题列表
  143. public static function getSpecsTitleList(string $keyword = '')
  144. {
  145. $db = Db::connect('mysql_wsm')
  146. ->name('specs')
  147. ->where('is_del', 0);
  148. if ($keyword != '') $db->whereLike('spec_name', '%' . $keyword . '%');
  149. $list = $db
  150. ->field('id spec_id,spec_name')
  151. ->order('addtime', 'desc')
  152. ->select()
  153. ->toArray();
  154. return json_show(0, '请求成功', $list);
  155. }
  156. //获取规格值列表
  157. public static function getSpecsValueByTitleList(int $spec_id = 0)
  158. {
  159. $list = Db::connect('mysql_wsm')
  160. ->name('spec_value')
  161. ->field('spec_id ,id spec_value_id,spec_value')
  162. ->where(['is_del' => 0, 'spec_id' => $spec_id])
  163. ->order('id')
  164. ->select()
  165. ->toArray();
  166. return json_show(0, '请求成功', $list);
  167. }
  168. //创建规格值
  169. public static function createSpec(array $param = [])
  170. {
  171. $url = env('WSM_DOMAIN') . 'abutment/createSpec';
  172. $res = json_decode(curl_request($url, $param), true);
  173. if (isset($res) && $res['code'] == CommonModel::$success) return json_show(CommonModel::$success, '创建规格值成功');
  174. else throw new Exception($res['message']);
  175. }
  176. //获取省市区列表
  177. public static function getAreaList(int $level = 1, string $pid_code = '', string $keyword = '')
  178. {
  179. switch ($level) {
  180. case 1:
  181. $list = Db::connect('mysql_wsm')
  182. ->name('province')
  183. ->field('province_code code,name');
  184. break;
  185. case 2:
  186. $list = Db::connect('mysql_wsm')
  187. ->name('city')
  188. ->field('city_code code,name')
  189. ->where('province_code', $pid_code);
  190. break;
  191. case 3:
  192. $list = Db::connect('mysql_wsm')
  193. ->name('area')
  194. ->field('area_code code,name')
  195. ->where('city_code', $pid_code);
  196. break;
  197. }
  198. if ($keyword != '') $list->whereLike('name', '%' . $keyword . '%');
  199. $data = $list->order('id')
  200. ->select()
  201. ->toArray();
  202. return json_show(0, '获取成功', $data);
  203. }
  204. //获取业务公司编码
  205. public static function getCompanyNoList(string $keyword = '')
  206. {
  207. $db = Db::connect('mysql_wsm')
  208. ->name('business')->where('is_del', 0);
  209. if ($keyword != '') $db->whereLike('company|companyNo', '%' . $keyword . '%');
  210. $list = $db
  211. ->field('companyNo,company')
  212. ->order('id')
  213. ->select()
  214. ->toArray();
  215. return json_show(0, '请求成功', $list);
  216. }
  217. //专属类型列表
  218. public static function getExclusiveList(int $pid = 0, string $keyword = '')
  219. {
  220. $where = [['status', '=', 1], ['is_del', '=', 0], ['pid', '=', $pid]];
  221. if ($keyword !== '') $where[] = ['name', 'like', '%' . $keyword . '%'];
  222. $data = Db::connect('mysql_wsm')
  223. ->name('exclusive')
  224. ->field('id exclusive_id,name exclusive_name,level')
  225. ->where($where)
  226. ->select()
  227. ->toArray();
  228. return json_show(0, '获取成功', $data);
  229. }
  230. //上传图片
  231. public static function uploadImg(array $files = [])
  232. {
  233. $url = env('WSM_DOMAIN') . 'abutment/uploadImg';
  234. // halt($files->getPath().DIRECTORY_SEPARATOR.$files->getFilename(),$files->getType(),$files->getBasename());
  235. // $data = array('file' => new \CURLFile(realpath($path)));
  236. $res = curl_upload($url, $files);
  237. halt('请求结果:', $res);
  238. $res = json_decode(curl_request($url, ['image' => $files->getPath() . DIRECTORY_SEPARATOR . $files->getFilename()]), true);
  239. halt($res);
  240. if (isset($res) && $res['code'] == CommonModel::$success) return json_show(CommonModel::$success, '上传图片成功', $res['data']);
  241. else throw new Exception($res['message']);
  242. }
  243. }