Store.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. 'store_logo' => $Tuanzhang['touxiang'],
  52. 'latitude' => $Tuanzhang['latitude'],
  53. 'longitude' => $Tuanzhang['longitude'],
  54. 'region_name' => $Tuanzhang['region_name'],
  55. 'province_name' => $Tuanzhang['province_name'],
  56. 'city_name' => $Tuanzhang['city_name'],
  57. 'district_name' => $Tuanzhang['district_name'],
  58. 'house_number' => $Tuanzhang['house_number'],
  59. 'cate_ids' => $Tuanzhang['cate_ids'],
  60. 'status' => $Tuanzhang['status'],
  61. ]);
  62. return self::where('tzid', $tzid)->find();
  63. }
  64. }
  65. public static function getTitlebyuid($uuid = '')
  66. {
  67. $mo = self::where('uuid', $uuid)->find();
  68. return $mo->title;
  69. }
  70. public static function getInfobyuid($uid)
  71. {
  72. $datatz = Tuanzhang::getInfobyuid($uid);
  73. if (!empty($datatz)) {
  74. $data = Store::getStorebytzid($datatz['id']);
  75. } else {
  76. $uuid = UuidRelation::getuuid($uid, 'store');
  77. if (!empty($uuid)) {
  78. $data = Store::where(['uuid' => $uuid])->find();
  79. if (!empty($data)) {
  80. $data = $data->toArray();
  81. }
  82. }
  83. }
  84. return $data;
  85. }
  86. public static function getpcarray()
  87. {
  88. $data = self::field('id,title')->where(['weid' => weid(), 'status' => 1])
  89. ->order('sort asc')
  90. ->select()->toArray();
  91. foreach ($data as $k => $v) {
  92. $array[$k]['val'] = $v['id'];
  93. $array[$k]['key'] = $v['title'];
  94. }
  95. return $array;
  96. }
  97. public static function conversion($vo)
  98. {
  99. if (empty($vo['stid'])) {
  100. $vo['stid'] = '未设置';
  101. } else {
  102. $vo['stid'] = StoreCate::getTitle($vo['stid']);
  103. }
  104. if ($vo['end_time'] == 0) {
  105. $vo['end_time'] = '永久有效';
  106. } else {
  107. $vo['end_time'] = time_format($vo['end_time']);
  108. }
  109. $vo['cate_ids'] = Category::getmultiple($vo['cate_ids']) ?? '无';
  110. if (!empty($vo['uuid'])) {
  111. $vo['username'] = Users::getusername($vo['uuid']);
  112. }
  113. $vo['region_name'] = $vo['province_name'] . $vo['city_name'] . $vo['district_name'];
  114. return $vo;
  115. }
  116. public static function setIncome($order_info)
  117. {
  118. if (empty($order_info['sid'])) {
  119. $uid = OrderStaff::getuuid($order_info['id']);
  120. if (!empty($uuid)) {
  121. $data = Technical::where('uuid', $uuid)->find();
  122. if (!empty($data)) {
  123. $order_info['sid'] = $data->sid;
  124. }
  125. }
  126. }
  127. if (!empty($order_info['sid'])) {
  128. $Store = Store::find($order_info['sid']);
  129. if (!empty($Store)) {
  130. $Store = $Store->toArray();
  131. }
  132. if (!empty($Store['status'])) {
  133. $percent = StoreCate::getPercent($Store['stid']);
  134. if (empty($percent)) {
  135. $percent = Config::getconfig('store')['return_percent'];
  136. }
  137. if ($percent > 0) {
  138. if (empty($order_info['cat_id'])) {
  139. $income = OrderGoods::getCommission($order_info, 'store', $percent);
  140. } else {
  141. $income = $order_info['total'];
  142. $income = ($income * percent_to_num($percent));
  143. }
  144. $return_percent = $percent;
  145. if ($income > 0) {
  146. if ($income > 0 && $income < 0.01) {
  147. $income = 0.01;
  148. }
  149. $StoreIncomelog = StoreIncomelog::where([
  150. 'sid' => $order_info['sid'],
  151. 'weid' => $order_info['weid'],
  152. 'order_id' => $order_info['id'],
  153. ])->find();
  154. if (empty($StoreIncomelog)) {
  155. Store::where('id', $order_info['sid'])->inc('income', $income)->update();
  156. Store::where('id', $order_info['sid'])->inc('total_income', $income)->update();
  157. $incomedata['sid'] = $order_info['sid'];
  158. $incomedata['ptype'] = 1;
  159. $incomedata['weid'] = $order_info['weid'];
  160. $incomedata['order_id'] = $order_info['id'];
  161. $incomedata['order_num_alias'] = $order_info['order_num_alias'];
  162. $incomedata['buyer_id'] = $order_info['uid'];
  163. $incomedata['income'] = $income;
  164. $incomedata['return_percent'] = floatval($return_percent);
  165. $incomedata['percentremark'] = $order_info['total'] . '% x' . $percent . '%';
  166. $incomedata['order_total'] = $order_info['total'];
  167. $incomedata['pay_time'] = $order_info['pay_time'];
  168. $incomedata['month_time'] = date('m', time());
  169. $incomedata['year_time'] = date('Y', time());
  170. $incomedata['order_status_id'] = 2; //已付款
  171. StoreIncomelog::create($incomedata);
  172. }
  173. }
  174. }
  175. }
  176. }
  177. }
  178. }