Store.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. <?php
  2. namespace app\model;
  3. use think\Model;
  4. class Store extends Model
  5. {
  6. protected $connection = 'mysql';
  7. protected $pk = 'id';
  8. protected $name = 'store';
  9. public static function getTitle($id = '')
  10. {
  11. $mo = self::find($id);
  12. return $mo->title;
  13. }
  14. public static function getUuid($id = '')
  15. {
  16. $mo = self::find($id);
  17. return $mo->uuid;
  18. }
  19. public static function getStorebytzid($tzid)
  20. {
  21. $mo = self::where('tzid', $tzid)->find();
  22. if (!empty($mo)) {
  23. return $mo->toArray();
  24. } else {
  25. $mo = self::createTuanzhang($tzid);
  26. if (!empty($mo)) {
  27. return $mo->toArray();
  28. }
  29. }
  30. }
  31. public static function getidbytzid($tzid)
  32. {
  33. $mo = self::where('tzid', $tzid)->find();
  34. if (!empty($mo)) {
  35. return $mo->id;
  36. } else {
  37. $mo = self::createTuanzhang($tzid);
  38. return $mo->id;
  39. }
  40. }
  41. public static function createTuanzhang($tzid)
  42. {
  43. $Tuanzhang = Tuanzhang::find($tzid);
  44. if (!empty($Tuanzhang)) {
  45. $Tuanzhang = $Tuanzhang->toArray();
  46. self::create([
  47. 'weid' => $Tuanzhang['weid'],
  48. 'tzid' => $Tuanzhang['id'],
  49. 'owner_name' => $Tuanzhang['title'],
  50. 'title' => $Tuanzhang['community_title'],
  51. 'tel' => $Tuanzhang['tel'],
  52. 'store_logo' => $Tuanzhang['touxiang'],
  53. 'latitude' => $Tuanzhang['latitude'],
  54. 'longitude' => $Tuanzhang['longitude'],
  55. 'region_name' => $Tuanzhang['region_name'],
  56. 'province_name' => $Tuanzhang['province_name'],
  57. 'city_name' => $Tuanzhang['city_name'],
  58. 'district_name' => $Tuanzhang['district_name'],
  59. 'house_number' => $Tuanzhang['house_number'],
  60. 'cate_ids' => $Tuanzhang['cate_ids'],
  61. 'status' => $Tuanzhang['status'],
  62. ]);
  63. return self::where('tzid', $tzid)->find();
  64. }
  65. }
  66. public static function getTitlebyuid($uuid = '')
  67. {
  68. $mo = self::where('uuid', $uuid)->find();
  69. return $mo->title;
  70. }
  71. public static function getInfobyuid($uid)
  72. {
  73. $datatz = Tuanzhang::getInfobyuid($uid);
  74. if (!empty($datatz)) {
  75. $data = Store::getStorebytzid($datatz['id']);
  76. } else {
  77. $uuid = UuidRelation::getuuid($uid, 'store');
  78. if (!empty($uuid)) {
  79. $data = Store::where(['uuid' => $uuid])->find();
  80. if (!empty($data)) {
  81. $data = $data->toArray();
  82. }
  83. }
  84. }
  85. return $data;
  86. }
  87. public static function getpcarray()
  88. {
  89. $data = self::field('id,title')->where(['weid' => weid(), 'status' => 1])
  90. ->order('sort asc')
  91. ->select()->toArray();
  92. foreach ($data as $k => $v) {
  93. $array[$k]['val'] = $v['id'];
  94. $array[$k]['key'] = $v['title'];
  95. }
  96. return $array;
  97. }
  98. public static function conversion($vo)
  99. {
  100. if (empty($vo['stid'])) {
  101. $vo['stid'] = '未设置';
  102. } else {
  103. $vo['stid'] = StoreCate::getTitle($vo['stid']);
  104. }
  105. if ($vo['end_time'] == 0) {
  106. $vo['end_time'] = '永久有效';
  107. } else {
  108. $vo['end_time'] = time_format($vo['end_time']);
  109. }
  110. $vo['cate_ids'] = Category::getmultiple($vo['cate_ids']) ?? '无';
  111. if (!empty($vo['uuid'])) {
  112. $vo['username'] = Users::getusername($vo['uuid']);
  113. }
  114. $vo['region_name'] = $vo['province_name'] . $vo['city_name'] . $vo['district_name'];
  115. $vo = RegisterField::conversion($vo);
  116. return $vo;
  117. }
  118. public static function getdiy_bycat($cat = 0, $count = 4, $Sort = "all", $ocid = 0)
  119. {
  120. $where['weid'] = weid();
  121. $where['status'] = 1;
  122. if ($cat > 0) {
  123. if (!empty($cat)) {
  124. $where['cate_ids'] = Category::getsonid($cat);
  125. }
  126. }
  127. $query = self::where($where);
  128. if ($ocid) {
  129. $query->where(function ($q) use ($ocid) {
  130. $Operatingcity = Operatingcity::find($ocid);
  131. if (!empty($Operatingcity)) {
  132. $Operatingcity = $Operatingcity->toArray();
  133. if (empty($Operatingcity['areatype'])) {
  134. $Operatingcity['areatype'] = 3;
  135. }
  136. if ($Operatingcity['areatype'] == 3) {
  137. $q->where('district_name', $Operatingcity['district_name'])->whereOr('district_name', '');
  138. } elseif ($Operatingcity['areatype'] == 2) {
  139. $q->where('city_name', $Operatingcity['city_name'])->whereOr('city_name', '');
  140. } elseif ($Operatingcity['areatype'] == 1) {
  141. $q->where('province_name', $Operatingcity['province_name'])->whereOr('province_name', '');
  142. }
  143. }
  144. });
  145. }
  146. if ($Sort == "all") {
  147. $Sort = 'sort asc,id desc';
  148. } elseif ($Sort == "sales") {
  149. $Sort = 'service_times desc';
  150. } elseif ($Sort == "price") {
  151. $Sort = 'create_time asc';
  152. }
  153. $data = $query->limit($count)
  154. ->order($Sort)->select()->toArray();
  155. foreach ($data as &$vo) {
  156. if (!empty($vo['tzid'])) {
  157. if (empty($vo['store_logo']) || empty($vo['title'])) {
  158. $Tuanzhang = Tuanzhang::find($vo['tzid']);
  159. if (!empty($Tuanzhang)) {
  160. $vo['store_logo'] = $Tuanzhang['touxiang'];
  161. $vo['title'] = $Tuanzhang['community_title'];
  162. }
  163. }
  164. }
  165. $vo['store_logo'] = toimg($vo['store_logo']);
  166. }
  167. return $data;
  168. }
  169. public static function setIncome($order_info)
  170. {
  171. if (empty($order_info['sid'])) {
  172. $uid = OrderStaff::getuuid($order_info['id']);
  173. if (!empty($uuid)) {
  174. $data = Technical::where('uuid', $uuid)->find();
  175. if (!empty($data)) {
  176. $order_info['sid'] = $data->sid;
  177. }
  178. }
  179. }
  180. if (!empty($order_info['sid'])) {
  181. $Store = Store::find($order_info['sid']);
  182. if (!empty($Store)) {
  183. $Store = $Store->toArray();
  184. }
  185. if (!empty($Store['status'])) {
  186. $percent = StoreCate::getPercent($Store['stid']);
  187. if (empty($percent)) {
  188. $percent = Config::getconfig('store')['return_percent'];
  189. }
  190. if ($percent > 0) {
  191. if (empty($order_info['cat_id'])) {
  192. $income = OrderGoods::getCommission($order_info, 'store', $percent);
  193. } else {
  194. $income = $order_info['total'];
  195. $income = ($income * percent_to_num($percent));
  196. }
  197. $return_percent = $percent;
  198. if ($income > 0) {
  199. if ($income > 0 && $income < 0.01) {
  200. $income = 0.01;
  201. }
  202. $StoreIncomelog = StoreIncomelog::where([
  203. 'sid' => $order_info['sid'],
  204. 'weid' => $order_info['weid'],
  205. 'order_id' => $order_info['id'],
  206. ])->find();
  207. if (empty($StoreIncomelog)) {
  208. Store::where('id', $order_info['sid'])->inc('income', $income)->update();
  209. Store::where('id', $order_info['sid'])->inc('total_income', $income)->update();
  210. $incomedata['sid'] = $order_info['sid'];
  211. $incomedata['ptype'] = 1;
  212. $incomedata['weid'] = $order_info['weid'];
  213. $incomedata['order_id'] = $order_info['id'];
  214. $incomedata['order_num_alias'] = $order_info['order_num_alias'];
  215. $incomedata['buyer_id'] = $order_info['uid'];
  216. $incomedata['income'] = $income;
  217. $incomedata['return_percent'] = floatval($return_percent);
  218. $incomedata['percentremark'] = $order_info['total'] . '% x' . $percent . '%';
  219. $incomedata['order_total'] = $order_info['total'];
  220. $incomedata['pay_time'] = $order_info['pay_time'];
  221. $incomedata['month_time'] = date('m', time());
  222. $incomedata['year_time'] = date('Y', time());
  223. $incomedata['order_status_id'] = 2; //已付款
  224. StoreIncomelog::create($incomedata);
  225. }
  226. }
  227. }
  228. }
  229. }
  230. }
  231. }