Consult.php 127 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\ActionLog;
  4. use app\admin\model\DataGroup as DataGroupModel;
  5. use app\admin\model\ProcessOrder;
  6. use think\App;
  7. use think\facade\Db;
  8. use think\facade\Validate;
  9. //竞价单(咨询单)
  10. class Consult extends Base
  11. {
  12. public $noble=[];
  13. public function __construct(App $app)
  14. {
  15. parent::__construct($app);
  16. $this->noble =\think\facade\Config::get("noble");
  17. }
  18. public function conlist(){
  19. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  20. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  21. $where=[['a.is_del',"=",0],['b.is_del',"=",0]];
  22. $infoNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  23. if ($infoNo !== "") {
  24. $where[] = ['a.infoNo','like','%'.$infoNo.'%'];
  25. }
  26. $salesman = isset($this->post['salesman']) && $this->post['salesman'] !== "" ? trim($this->post['salesman']) : "";
  27. if ($salesman !== "") {
  28. //$where["salesman"] =Db::Raw("like '%$salesman%'");
  29. $where[]= ["b.salesman",'like',"%$salesman%"];
  30. }
  31. $cpName = isset($this->post['cpName']) && $this->post['cpName'] !== "" ? trim($this->post['cpName']) : "";
  32. if ($cpName !== "") {
  33. //$where["cpName"]= Db::Raw("like '%$cpName%'");
  34. $where[]= ["a.good_Name",'like',"%$cpName%"];
  35. }
  36. $khNo = isset($this->post['khNo']) && $this->post['khNo'] !== "" ? trim($this->post['khNo']) : "";
  37. if ($khNo !== "") {
  38. // $where['khNo'] = $khNo;
  39. $where[]= ["b.khNo",'like',"%$khNo%"];
  40. }
  41. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
  42. if ($companyNo !== "") {
  43. // $where['khNo'] = $khNo;
  44. $where[]= ["b.companyNo",'like',"%$companyNo%"];
  45. }
  46. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
  47. if ($start !="") {
  48. //$where = ["zxtime"=>Db::raw(">= '{$start}'")];
  49. $where[]= ["a.addtime",'>=',$start];
  50. }
  51. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
  52. if($end !=""){
  53. $where[]= ["a.addtime",'<=',$end];
  54. }
  55. $status = isset($this->post['status']) && $this->post['status'] !== "" ? trim($this->post['status']) : "";
  56. if ($status !== "") {
  57. $where[]= ["a.status",'=',$status];
  58. }
  59. $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  60. if ($company_name !== "") $where[] = ["b.createrid", 'in', get_company_item_user_by_name($company_name)];
  61. // $role=$this->checkRole();
  62. // if(!empty($role['write'])){
  63. // $where[]=["b.createrid","in",$role['write']];
  64. // }
  65. $role = $this->checkDataShare();
  66. if (!empty($role[DataGroupModel::$type_全部])) $where[] = ["b.createrid", "in", $role[DataGroupModel::$type_全部]];
  67. // if(!empty($role['platform']) ){
  68. // $where[]=["b.platform_code","in",$role['platform']];
  69. // }
  70. $count = Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)
  71. ->count();
  72. $total = ceil($count / $size);
  73. $page = $page >= $total ? $total : $page;
  74. $list = Db::name('consult_info')
  75. ->alias("a")
  76. ->leftJoin("consult_order b", "a.zxNo=b.zxNo")
  77. ->leftJoin("depart_user u", "u.uid=b.createrid AND u.is_del=0")
  78. ->where($where)
  79. ->page($page, $size)
  80. ->field("a.*,b.createrid,b.creater,b.is_project,b.projectNo,b.khNo,b.endtime,b.platform_code,b.saleid,b.salesman,b.depart,u.itemid")
  81. ->order("a.id desc")
  82. ->cursor();
  83. $data=[];
  84. foreach ($list as $value){
  85. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  86. $value['specinfo']=isset($value['specinfo'])&&$value['specinfo']!=""? json_decode($value['specinfo'],
  87. true):[];
  88. $brand = Db::name("brand")->where(['id'=>$value['brand_id']])->find();
  89. $value['brand_name']= isset($brand['brand_name']) && $brand['brand_name']!='' ? $brand['brand_name']:"";
  90. $value['khname']="";
  91. if($value['khNo']!==""){
  92. $kh=Db::name("customer_info")->where(['companyNo'=>$value['khNo']])->find();
  93. $value['khname']= isset($kh['companyName'])?$kh['companyName']:"";
  94. }
  95. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  96. $value['company_name'] = implode('/', array_column(GetPart($value['itemid']), 'name'));
  97. //是否具有编辑权限
  98. $value['is_allow_update'] = 0;
  99. if (in_array($this->roleid, [1, 33]) || in_array($value['createrid'], $role[DataGroupModel::$type_可编辑])) $value['is_allow_update'] = 1;
  100. $data[]=$value;
  101. }
  102. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  103. }
  104. public function info(){
  105. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) : "";
  106. if($id==""){
  107. return error_show(1002,"咨询单编号不能为空");
  108. }
  109. $fo = Db::name('consult')->where(['id'=>$id,'is_del'=>0])->find();
  110. $in= isset($fo['cat_id']) && $fo['cat_id'] !=0 ? made($fo['cat_id']):[];
  111. $fo['can']=$in;
  112. if(empty($fo)){
  113. return error_show(1002,"未找到咨询单编号");
  114. }else{
  115. return app_show(0,"获取成功",$fo);
  116. }
  117. }
  118. public function del(){
  119. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) : "";
  120. $de = Db::name('consult')->where(['id'=>$id,'is_del'=>0])->find();
  121. if($de==false){
  122. return error_show(1002,'咨询单信息未找到');
  123. }
  124. $dell= Db::name('consult')->update(['id'=>$id,'is_del'=>1,'updatetime'=>date("Y-m-d H:i:s")]);
  125. if($dell){
  126. return error_show(0,"删除成功");
  127. }else
  128. return error_show(1002,"删除失败");
  129. }
  130. public function create(){
  131. $is_project= isset($this->post['is_project']) && $this->post['is_project'] !=="" ? intval($this->post['is_project']) : "";
  132. if($is_project===""){
  133. return error_show(1002,"参数is_project不能为空");
  134. }
  135. if($is_project==1){
  136. $projectNo= isset($this->post['projectNo']) && $this->post['projectNo'] !=="" ? trim($this->post['projectNo']) : "";
  137. if($projectNo===""){
  138. return error_show(1002,"参数projectNo不能为空");
  139. }
  140. }
  141. $khNo = isset($this->post['khNo']) && $this->post['khNo'] !=="" ? trim($this->post['khNo']) : "";
  142. if($khNo===""){
  143. return error_show(1002,"参数khNo不能为空");
  144. }
  145. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !=="" ? trim($this->post['companyNo']) : "";
  146. if($companyNo===""){
  147. return error_show(1002,"参数companyNo不能为空");
  148. }
  149. $endtime = isset($this->post['endtime']) && $this->post['endtime'] !=="" ? $this->post['endtime'] : "";
  150. if($endtime===""){
  151. return error_show(1002,"参数endtime不能为空");
  152. }
  153. $platform_code = isset($this->post['platform_code']) && $this->post['platform_code'] !=="" ? trim($this->post['platform_code']) :
  154. "";
  155. if($platform_code===""){
  156. return error_show(1002,"参数platform_code不能为空");
  157. }
  158. $ladder = isset($this->post['ladder'])&&!empty($this->post['ladder']) ? $this->post['ladder']:"";
  159. if($ladder==""){
  160. return error_show(1005,"参数ladder不能为空");
  161. }
  162. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  163. if($token==''){
  164. return error_show(105,"参数token不能为空");
  165. }
  166. $user =GetUserInfo($token);
  167. if(empty($user)||$user['code']!=0){
  168. return error_show(102,"用户数据不存在");
  169. }
  170. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  171. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  172. $depart= Db::name("depart_user")->where(["uid"=>$createrid,"status"=>1,"is_del"=>0])->find();
  173. $zxNo=makeNo("ZX");
  174. Db::startTrans();
  175. try{
  176. $data=[
  177. "zxNo"=>$zxNo,
  178. "createrid"=>$createrid,
  179. "creater"=>$creater,
  180. "is_project"=>$is_project,
  181. "projectNo"=>isset($projectNo) ? $projectNo:"",
  182. "khNo"=>$khNo,
  183. "companyNo"=>$companyNo,
  184. "endtime"=>$endtime,
  185. "salesman"=>$creater,
  186. "platform_code"=>$platform_code,
  187. "saleid"=>$createrid,
  188. "depart"=>isset($depart['itemid'])?$depart['itemid']:0,
  189. "status"=>0,
  190. "is_del"=>0,
  191. "addtime"=>date("Y-m-d H:i:s"),
  192. "updatetime"=>date("Y-m-d H:i:s"),
  193. ];
  194. $zx = Db::name("consult_order")->insert($data);
  195. if($zx){
  196. //判断是否是项目,且该项目是否存在台账记录中
  197. if($is_project==1) $stand_exists=Db::name('standing_book')->field('id')->where('projectNo',$projectNo)->find();
  198. foreach ($ladder as $value){
  199. $infoNo=makeNo("IF");
  200. $specinfo=[];
  201. if(isset($value['specinfo']) &&!empty($value['specinfo'])){
  202. foreach ($value["specinfo"] as $v){
  203. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  204. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  205. $v['spec_name']=isset($spec['spec_name'])? $spec['spec_name']:"";
  206. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"" ;
  207. $specinfo[]=$v;
  208. }
  209. }
  210. $info=[
  211. "infoNo"=>$infoNo,
  212. "zxNo"=>$zxNo,
  213. "spuCode"=>"",
  214. "good_name"=>$value['good_name'],
  215. "good_img"=>$value['good_img'],
  216. "cat_id"=>$value['cat_id'],
  217. "unit"=>$value['unit'],
  218. "brand_id"=>$value['brand_id'],
  219. "arrival_time"=>$value['arrival_time'],
  220. "specinfo"=>empty($specinfo)?"" : json_encode($specinfo),
  221. "cost_desc" => isset($value['cost_desc']) ? $value['cost_desc'] : '',
  222. "is_addrs"=>$value['is_addrs'],
  223. "is_custom"=>$value['is_custom'],
  224. "metal_id"=>$value['metal_id'],
  225. "config"=>isset($value['config'])?$value['config']:"",
  226. "other_config"=>isset($value['other_config'])?$value['other_config']:"",
  227. "specs_weight"=>isset($value['specs_weight'])?$value['specs_weight']:"0",
  228. "gold_price"=>isset($value['gold_price'])?$value['gold_price']:"0",
  229. "is_gold_price"=>isset($value['is_gold_price'])?$value['is_gold_price']:"0",
  230. "total_weight"=>isset($value['total_weight'])?$value['total_weight']:"0",
  231. "budget_price"=>$value['budget_price'],
  232. "num"=>$value['num'],
  233. "pgNo"=>isset($value['pgNo'])&&$value['pgNo']!==""?trim($value['pgNo']):"",
  234. "use_desc"=>$value['use_desc'],
  235. "remark"=>$value['remark'],
  236. "status"=>1,
  237. "is_del"=>0,
  238. "addtime"=>date("Y-m-d H:i:s"),
  239. "updatetime"=>date("Y-m-d H:i:s"),
  240. 'enclosure_file'=>isset($value['enclosure_file'])?$value['enclosure_file']:'',
  241. ];
  242. $up = Db::name("consult_info")->insertGetId($info);
  243. if(!$up){
  244. Db::rollback();
  245. return error_show(1004,'添加失败');
  246. }else{
  247. //修改状态
  248. ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
  249. "order_code" => $infoNo,//咨询单详情编号
  250. "status" => 1,//这里的status是之前的值
  251. "action_remark" => '',//备注
  252. "action_type" => "create"//新建create,编辑edit,更改状态status
  253. ], "ZXD", 1, $info);
  254. //竞价单不走流程,不推待办已办
  255. // ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
  256. // "order_type" => 'ZXD',
  257. // "order_code" => $infoNo,//咨询单详情编号
  258. // "order_id" => $up,
  259. // "order_status" => 1,
  260. // 'before_status'=>0
  261. // ]);
  262. //如果存在该项目编码,更新对应的第一个竞价单编码,其他竞价单编码新增(带着项目编码)
  263. if (isset($stand_exists)) {
  264. Db::name('standing_book')
  265. ->where('id', $stand_exists['id'])
  266. ->update([
  267. 'infoNo' => $infoNo,
  268. 'updatetime' => date('Y-m-d H:i:s')
  269. ]);
  270. unset($stand_exists);//后面的竞价单编码不用更新,都是新增
  271. } else {
  272. //添加台账信息
  273. Db::name('standing_book')
  274. ->insert([
  275. 'standBookNo' => makeNo("IO"),
  276. 'projectNo' => isset($projectNo) ? $projectNo : '',
  277. 'infoNo' => $infoNo,
  278. 'companyNo' => $companyNo,
  279. 'customer_code' => $khNo,
  280. 'addtime' => date('Y-m-d H:i:s'),
  281. 'updatetime' => date('Y-m-d H:i:s')
  282. ]);
  283. }
  284. }
  285. }
  286. Db::commit();
  287. return app_show(0,"新建成功",["zxNo"=>$zxNo]);
  288. }else{
  289. Db::rollback();
  290. return error_show(1004,"新建失败");
  291. }
  292. }catch (\Exception $e){
  293. Db::rollback();
  294. return error_show(1003,$e->getMessage());
  295. }
  296. }
  297. public function zxinfo(){
  298. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  299. if($infoNo==""){
  300. return error_show(1004,"参数infoNo不能为空");
  301. }
  302. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  303. if($zxinfo==false){
  304. return error_show(1004,"未找到信息数据");
  305. }
  306. $zxorder = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo'],"is_del"=>0])->find();
  307. if($zxorder==false){
  308. return error_show(1004,"未找到咨询信息数据");
  309. }
  310. $cat =Db::name("cat")->where(["id"=>$zxinfo['cat_id']])->find();
  311. $budget = isset($cat['order_rate']) ? $cat['order_rate']:0;
  312. $zxinfo['can']= isset($zxinfo['cat_id']) && $zxinfo['cat_id'] !=0 ? made($zxinfo['cat_id'],[]):[];
  313. $zxinfo['khname']="";
  314. $zxinfo['original_price']=sprintf("%.2f",$zxinfo['budget_price']* (1 -$budget/100));
  315. $zxinfo['khNo']="";
  316. $zxinfo['brand_id']=$zxinfo['brand_id']==0 ?"":$zxinfo['brand_id'];
  317. $zxinfo['brand']="";
  318. $zxinfo['companyNo']=isset($zxorder['companyNo'])?$zxorder['companyNo']:"";
  319. $zxinfo['projectNo']=isset($zxorder['projectNo'])?$zxorder['projectNo']:"";
  320. $zxinfo['is_project']=isset($zxorder['is_project'])?$zxorder['is_project']:"";
  321. $zxinfo['company']="";
  322. $zxinfo['endtime']=isset($zxorder['endtime'])?$zxorder['endtime']:"";
  323. $zxinfo['platform_code'] =isset($zxorder['platform_code'])?$zxorder['platform_code']:"";
  324. $zxinfo['salesman'] =isset($zxorder['salesman'])?$zxorder['salesman']:"";
  325. $zxinfo['saleid'] =isset($zxorder['saleid'])?$zxorder['saleid']:"";
  326. $zxinfo['depart'] =isset($zxorder['depart'])?$zxorder['depart']:"";
  327. $zxinfo['project_name']="";
  328. $zxinfo['budget_total']="";
  329. $zxinfo['departinfo']=[];
  330. $zxinfo['unit_name']="";
  331. $zxinfo['metal_name']=isset($zxinfo['metal_id'])&& $zxinfo['metal_id']!=0?$this->noble[$zxinfo['metal_id']]:"";
  332. $zxinfo['specinfo']=json_decode($zxinfo['specinfo'],true);
  333. if($zxorder['khNo']!==""){
  334. $kh=Db::name("customer_info")->where(['companyNo'=>$zxorder['khNo']])->find();
  335. $zxinfo['khname']= isset($kh['companyName'])?$kh['companyName']:"";
  336. $zxinfo['khNo']= $zxorder['khNo'];
  337. }
  338. if($zxinfo['unit']!==""){
  339. $unit=Db::name("unit")->where(['id'=>$zxinfo['unit']])->find();
  340. $zxinfo['unit_name']= isset($unit['unit'])?$unit['unit']:"";
  341. }
  342. if($zxinfo['brand_id']!==""){
  343. $unit=Db::name("brand")->where(['id'=>$zxinfo['brand_id']])->find();
  344. $zxinfo['brand']= isset($unit['brand_name'])?$unit['brand_name']:"";
  345. }
  346. if($zxorder['companyNo']!==""){
  347. $kh=Db::name("business")->where(['companyNo'=>$zxorder['companyNo']])->find();
  348. $zxinfo['company']= isset($kh['company'])?$kh['company']:"";
  349. }
  350. if($zxorder['is_project']==1 && $zxorder['projectNo']!==""){
  351. $project = Db::name("project")->where(["projectNo"=>$zxorder['projectNo'],"is_del"=>0])->find();
  352. $zxinfo['project_name']=isset($project['project_name'])?$project['project_name']:"";
  353. $zxinfo['budget_total']=isset($project['budget_total'])?$project['budget_total']:"";
  354. $zxinfo['project_use_desc']=isset($project['use_desc'])?$project['use_desc']:"";
  355. $projectinfo = Db::name("project_info")->where(["pgNo"=>$zxinfo['pgNo']])->find();
  356. $zxinfo['pgNo'] = isset($projectinfo['pgNo']) ? $projectinfo['pgNo']:"";
  357. }
  358. if($zxorder['depart']>0){
  359. $zxinfo['departinfo']=GetPart($zxorder['depart']);
  360. }
  361. if($zxorder['platform_code']>0){
  362. $palt=Db::name("platform")->where(["id"=>$zxorder['platform_code']])->find();
  363. $zxinfo['platform_name']=isset($palt['platform_name'])?$palt['platform_name']:"";
  364. }
  365. return app_show(0,"获取成功",$zxinfo);
  366. }
  367. public function zxedit(){
  368. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  369. if($infoNo==""){
  370. return error_show(1004,"参数infoNo不能为空");
  371. }
  372. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  373. if($zxinfo==false){
  374. return error_show(1004,"未找到信息数据");
  375. }
  376. $enclosure_file =isset($this->post['enclosure_file'])&&$this->post['enclosure_file']!=""?trim($this->post['enclosure_file']):$zxinfo['enclosure_file'];
  377. $good_name= isset($this->post['good_name'])&&$this->post['good_name']!=""?trim($this->post['good_name']):"";
  378. if($good_name==""){
  379. return error_show(1003,"参数good_name不能为空");
  380. }
  381. $good_img= isset($this->post['good_img'])&&$this->post['good_img']!=""?trim($this->post['good_img']):"";
  382. if($good_img==""){
  383. return error_show(1003,"参数good_img不能为空");
  384. }
  385. $cat_id= isset($this->post['cat_id'])&&$this->post['cat_id']!=""?intval($this->post['cat_id']):"";
  386. if($cat_id==""){
  387. return error_show(1003,"参数cat_id不能为空");
  388. }
  389. $unit= isset($this->post['unit'])&&$this->post['unit']!=""?trim($this->post['unit']):"";
  390. if($unit==""){
  391. return error_show(1003,"参数unit不能为空");
  392. }
  393. $brand_id= isset($this->post['brand_id'])&&$this->post['brand_id']!==""?intval($this->post['brand_id']):"0";
  394. $arrival_time= isset($this->post['arrival_time'])&&$this->post['arrival_time']!=""?$this->post['arrival_time']:"";
  395. if($arrival_time==""){
  396. return error_show(1003,"参数arrival_time不能为空");
  397. }
  398. $specin= isset($this->post['specinfo'])&&!empty($this->post['specinfo'])?$this->post['specinfo']:"";
  399. if($specin==""){
  400. return error_show(1003,"参数specinfo不能为空");
  401. }
  402. $cost_desc= isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""?trim($this->post['cost_desc']):"";
  403. // if($cost_desc==""){
  404. // return error_show(1003,"参数cost_desc不能为空");
  405. // }
  406. $is_addrs= isset($this->post['is_addrs'])&&$this->post['is_addrs']!==""?intval($this->post['is_addrs']):"";
  407. if($is_addrs===""){
  408. return error_show(1003,"参数is_addrs不能为空");
  409. }
  410. $is_custom= isset($this->post['is_custom'])&&$this->post['is_custom']!==""?trim($this->post['is_custom']):"";
  411. if($is_custom===""){
  412. return error_show(1003,"参数is_custom不能为空");
  413. }
  414. $metal_id= isset($this->post['metal_id'])&&$this->post['metal_id']!==""?intval($this->post['metal_id']):"";
  415. if($metal_id===""){
  416. return error_show(1003,"参数metal_id不能为空");
  417. }
  418. $config = isset($this->post['config'])&& $this->post['config']!=""?trim($this->post['config']):"";
  419. $other_config = isset($this->post['other_config'])&& $this->post['other_config']!=""?trim($this->post['other_config']):"";
  420. $specs_weight = isset($this->post['specs_weight'])&& $this->post['specs_weight']!==""?floatval($this->post['specs_weight']):"";
  421. $gold_price = isset($this->post['gold_price'])&& $this->post['gold_price']!==""?floatval($this->post['gold_price']):"";
  422. $is_gold_price = isset($this->post['is_gold_price'])&& $this->post['is_gold_price']!==""?intval($this->post['is_gold_price']):"0";
  423. $budget_price = isset($this->post['budget_price'])&& $this->post['budget_price']!==""?floatval($this->post['budget_price']):"";
  424. $total_weight = isset($this->post['total_weight'])&& $this->post['total_weight']!==""?floatval($this->post['total_weight']):"";
  425. $num = isset($this->post['num'])&& $this->post['num']!==""?intval($this->post['num']):"";
  426. if($num===""){
  427. return error_show(1003,"参数num不能为空");
  428. }
  429. if($budget_price===""){
  430. return error_show(1003,"参数budget_price不能为空");
  431. }
  432. $pgNo = isset($this->post['pgNo'])&& $this->post['pgNo']!="" ? trim($this->post['pgNo']):"";
  433. $use_desc = isset($this->post['use_desc'])&& $this->post['use_desc']!="" ? trim($this->post['use_desc']):"";
  434. if($use_desc==""){
  435. return error_show(1003,"参数use_desc不能为空");
  436. }
  437. $remark = isset($this->post['remark'])&& $this->post['remark']!="" ? trim($this->post['remark']):"";
  438. if($remark==""){
  439. return error_show(1003,"参数remark不能为空");
  440. }
  441. $endtime = isset($this->post['endtime'])&& $this->post['endtime']!="" ? trim($this->post['endtime']):"";
  442. if($endtime==""){
  443. return error_show(1003,"参数endtime不能为空");
  444. }
  445. if($metal_id!=0){
  446. if($config==""){
  447. return error_show(1003,"参数config不能为空");
  448. }
  449. if($other_config==""){
  450. return error_show(1003,"参数other_config不能为空");
  451. }
  452. if($specs_weight===""){
  453. return error_show(1003,"参数specs_weight不能为空");
  454. }
  455. if($gold_price===""){
  456. return error_show(1003,"参数gold_price不能为空");
  457. }
  458. }
  459. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  460. if($token==''){
  461. return error_show(102,"参数token不能为空");
  462. }
  463. $user =GetUserInfo($token);
  464. if(empty($user)||$user['code']!=0){
  465. return error_show(105,"用户数据不存在");
  466. }
  467. $specinfo=[];
  468. foreach ($specin as $v){
  469. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  470. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  471. $v['spec_name']=isset($spec['spec_name'])?$spec['spec_name']:"";
  472. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"";
  473. $specinfo[]=$v;
  474. }
  475. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  476. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  477. $bidlist = Db::name("consult_bids")->where(["infoNo"=>$zxinfo['infoNo'],"is_del"=>0])->select();
  478. Db::startTrans();
  479. try{
  480. $innew =makeNo("IF");
  481. $info=[
  482. "infoNo"=>$innew,
  483. "zxNo"=>$zxinfo['zxNo'],
  484. "spuCode"=>"",
  485. "good_name"=>$good_name,
  486. "good_img"=>$good_img,
  487. "cat_id"=>$cat_id,
  488. "unit"=>$unit,
  489. "brand_id"=>$brand_id,
  490. "arrival_time"=>$arrival_time,
  491. "specinfo"=>json_encode($specinfo),
  492. // "color"=>$color,
  493. // "material"=>$material,
  494. "cost_desc"=>$cost_desc,
  495. "is_addrs"=>$is_addrs,
  496. "is_custom"=>$is_custom,
  497. "metal_id"=>$metal_id,
  498. "config"=>$config,
  499. "other_config"=>$other_config,
  500. "specs_weight"=>$specs_weight===""?0:$specs_weight,
  501. "gold_price"=>$gold_price===""? 0 : $gold_price,
  502. "is_gold_price"=>$is_gold_price===""?0:$is_gold_price,
  503. "total_weight"=>$total_weight===""? $num*$specs_weight :$total_weight,
  504. "budget_price"=>$budget_price,
  505. "num"=>$num,
  506. "pgNo"=>$pgNo,
  507. "use_desc"=>$use_desc,
  508. "remark"=>$remark,
  509. "bargain_num"=>$zxinfo['bargain_num']+1,
  510. "status"=>1,
  511. "is_del"=>0,
  512. "addtime"=>date("Y-m-d H:i:s"),
  513. "updatetime"=>date("Y-m-d H:i:s"),
  514. 'bargain_status'=>1,
  515. 'enclosure_file'=>$enclosure_file
  516. ];
  517. $up = Db::name("consult_info")->insert($info);
  518. if($up){
  519. //操作记录
  520. ActionLog::logAdd($this->post['token'], [
  521. "order_code" => $innew,//咨询单详情编号
  522. "status" => 1,//这里的status是之前的值
  523. "action_remark" => '',//备注
  524. "action_type" => "edit"//新建create,编辑edit,更改状态status
  525. ], "ZXD", 1, $this->post);
  526. // ProcessOrder::AddProcess($this->post['token'], [
  527. // "order_type" => 'ZXD',
  528. // "order_code" => $innew,//咨询单详情编号
  529. // "order_id" => 0,
  530. // "order_status" => 1
  531. // ]);
  532. if (!empty($bidlist)){
  533. foreach ($bidlist as $value){
  534. unset($value['id']);
  535. $value['infoNo']=$innew;
  536. $value['bidNo']=makeNo("BD");
  537. $value['spuCode']=makeNo("SKU");
  538. $value['status'] =0;
  539. $value['updatetime'] =date("Y-m-d H:i:s");
  540. $in = Db::name("consult_bids")->insert($value);
  541. if($in==false){
  542. Db::rollback();
  543. return error_show(1004,"反馈商品新建失败");
  544. }
  545. ActionLog::logAdd($this->post['token'], [
  546. "order_code" => $innew,//咨询单详情编号
  547. "status" => 1,//这里的status是之前的值
  548. "action_remark" => '',//备注
  549. "action_type" => "edit"//新建create,编辑edit,更改状态status
  550. ], "FKD", 1, $this->post);
  551. }
  552. }
  553. $zxinfo["bargain_status"] =1;
  554. $zxinfo["status"] =6;
  555. $zxinfo["bargain_code"] =$innew;
  556. $zxinfo["updatetime"] =date("Y-m-d H:i:s");
  557. $bar=Db::name("consult_info")->save($zxinfo);
  558. if($bar==false){
  559. Db::rollback();
  560. return error_show(1004,"反馈商品更新失败");
  561. }else{
  562. //修改状态,添加待办
  563. ActionLog::logAdd($this->post['token'], [
  564. "order_code" => $zxinfo['infoNo'],//咨询单详情编号
  565. "status" => $zxinfo['status'],//这里的status是之前的值
  566. "action_remark" => '',//备注
  567. "action_type" => "edit"//新建create,编辑edit,更改状态status
  568. ], "ZXD", $zxinfo['status'], $zxinfo);
  569. }
  570. //更新consule_order记录
  571. $op = Db::name('consult_order')->where('zxNo',$zxinfo['zxNo'])->update(['endtime'=>$endtime,
  572. 'updatetime'=>date('Y-m-d H:i:s')]);
  573. if($op==false){
  574. Db::rollback();
  575. return error_show(1004,'咨询单结束时间更新失败');
  576. }
  577. //维护台账记录
  578. $insert_standing_book_data=[
  579. 'standBookNo'=>makeNo('IO'),
  580. 'infoNo'=>$innew,
  581. 'addtime' => date('Y-m-d H:i:s'),
  582. 'updatetime' => date('Y-m-d H:i:s')
  583. ];
  584. $temp_project = Db::name('consult_order')->field('id,projectNo,khNo,companyNo')->where(['zxNo'=>$zxinfo['zxNo'], 'is_del'=>0])->find();
  585. if(!empty($temp_project)){
  586. $insert_standing_book_data['projectNo']=$temp_project['projectNo'];
  587. $insert_standing_book_data['companyNo']=$temp_project['companyNo'];
  588. $insert_standing_book_data['customer_code']=$temp_project['khNo'];
  589. }
  590. Db::name('standing_book')->insert($insert_standing_book_data);
  591. Db::commit();
  592. return app_show(0,"咨询新建成功",["infoNo"=>$innew]);
  593. }
  594. }catch (\Exception $e){
  595. Db::rollback();
  596. return error_show(1004,$e->getMessage());
  597. }
  598. }
  599. //** 发布竞标任务 */
  600. public function bargain(){
  601. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  602. if($infoNo==""){
  603. return error_show(1004,"参数infoNo不能为空");
  604. }
  605. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  606. if($zxinfo==false){
  607. return error_show(1004,"未找到信息数据");
  608. }
  609. $status =isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status']):"";
  610. if($status===""){
  611. return error_show(1004,"参数status不能为空");
  612. }
  613. // if($status==1&&$zxinfo['status']>1){
  614. // $zxinfo['bargain_num']=+1;
  615. // }
  616. $old_zxinfo_status = $zxinfo['status'];
  617. $zxinfo['status']=$status;
  618. $zxinfo['updatetime']=date("Y-m-d H:i:s");
  619. $up = Db::name("consult_info")->save($zxinfo);
  620. if($up){
  621. //修改状态,添加待办
  622. ActionLog::logAdd($this->post['token'], [
  623. "order_code" => $zxinfo['infoNo'],//咨询单详情编号
  624. "status" => $old_zxinfo_status,//这里的status是之前的值
  625. "action_remark" => '',//备注
  626. "action_type" => "status"//新建create,编辑edit,更改状态status
  627. ], "ZXD", $zxinfo['status'], $zxinfo);
  628. return app_show(0,"状态更新成功");
  629. }else{
  630. return error_show(1003,"状态更新失败");
  631. }
  632. }
  633. //反馈商品添加
  634. public function feadback(){
  635. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  636. if($infoNo==""){
  637. return error_show(1002,"参数infoNo不能为空");
  638. }
  639. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  640. if($zxinfo==false){
  641. return error_show(1003,"未找到信息数据");
  642. }
  643. if($zxinfo['status']!=1){
  644. return error_show(1004,"任务未进行");
  645. }
  646. $zx = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo'],"is_del"=>0])->find();
  647. if($zx==false){
  648. return error_show(1003,"未找咨询信息数据");
  649. }
  650. $pname = isset($this->post['pname'])&&$this->post['pname']!=""? trim($this->post['pname']):"";
  651. if($pname==""){
  652. return error_show(1002,"参数pname不能为空");
  653. }
  654. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"";
  655. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? trim($this->post['cat_id']):"";
  656. if($cat_id==""){
  657. return error_show(1002,"参数cat_id不能为空");
  658. }
  659. $specin= isset($this->post['specinfo'])&&!empty($this->post['specinfo'])?$this->post['specinfo']:"";
  660. if($specin==""){
  661. return error_show(1003,"参数specinfo不能为空");
  662. }
  663. $specinfo=[];
  664. foreach ($specin as $v){
  665. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  666. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  667. $v['spec_name']=isset($spec['spec_name'])?$spec['spec_name']:"";
  668. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"";
  669. $specinfo[]=$v;
  670. }
  671. $unit_id = isset($this->post['unit_id'])&&$this->post['unit_id']!=""? intval($this->post['unit_id']):"";
  672. $cost_desc = isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""? trim($this->post['cost_desc']):"";
  673. $work_day = isset($this->post['work_day'])&&$this->post['work_day']!=""? intval($this->post['work_day']):"";
  674. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!=""? intval($this->post['delivery_day']):"";
  675. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""? $this->post['good_img']:[];
  676. $expire_day = isset($this->post['expire_day'])&&$this->post['expire_day']!=""? intval($this->post['expire_day']) :"";
  677. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!=""? trim($this->post['origin_place']):"";
  678. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
  679. $pay_way = isset($this->post['pay_way'])&&$this->post['pay_way']!=""? intval($this->post['pay_way']):"";
  680. $tax = isset($this->post['tax'])&&$this->post['tax']!=""? trim($this->post['tax']):"";
  681. $send_way = isset($this->post['send_way'])&&$this->post['send_way']!=""? intval($this->post['send_way']):"";
  682. $metal_id = isset($this->post['metal_id'])&&$this->post['metal_id']!=""? intval($this->post['metal_id']):"0";
  683. $is_gold_price = isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!=""? intval($this->post['is_gold_price']):"0";
  684. $config = isset($this->post['config'])&&$this->post['config']!=""? $this->post['config']:"";
  685. $other_config = isset($this->post['other_config'])&&$this->post['other_config']!=""? $this->post['other_config']:"";
  686. $weight = isset($this->post['weight'])&&$this->post['weight']!==""? floatval($this->post['weight']):"0";
  687. $good_weight = isset($this->post['noble_weight'])&&$this->post['noble_weight']!==""? floatval($this->post['noble_weight']):"0";
  688. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!==""? floatval($this->post['demo_fee']):"0";
  689. $delivery_fee = isset($this->post['delivery_fee'])&&$this->post['delivery_fee']!==""? floatval($this->post['delivery_fee']):"0";
  690. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!==""? floatval($this->post['open_fee']):"0";
  691. $pakge_fee = isset($this->post['pakge_fee'])&&$this->post['pakge_fee']!==""? floatval($this->post['pakge_fee']):"0";
  692. $nake_fee = isset($this->post['nake_fee'])&&$this->post['nake_fee']!==""? floatval($this->post['nake_fee']):"0";
  693. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!==""? floatval($this->post['mark_fee']):"0";
  694. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!==""? floatval($this->post['cert_fee']):"0";
  695. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!==""? floatval($this->post['cost_fee']):"0";
  696. if($nake_fee==="" ){
  697. return error_show(1004,"参数nake_fee不能为空");
  698. }
  699. $is_diff = isset($this->post['is_diff'])&&$this->post['is_diff']!==""? intval($this->post['is_diff']):"";
  700. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  701. $remark = isset($this->post['remark'])&&$this->post['remark']!=""? trim($this->post['remark']):"";
  702. $delivery_place = isset($this->post['delivery_place'])&& $this->post['delivery_place']!='' ? trim($this->post['delivery_place']):"";
  703. if($delivery_place==''){
  704. return error_show(1002,"参数delivery_place不能为空");
  705. }
  706. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  707. if($token==''){
  708. return error_show(1002,"参数token不能为空");
  709. }
  710. $user =GetUserInfo($token);
  711. if(empty($user)||$user['code']!=0){
  712. return error_show(1005,"用户数据不存在");
  713. }
  714. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  715. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  716. $bidNo=makeNo("BD");
  717. $spucode=makeNo("SKU");
  718. $catinfo = Db::name("cat")->where(["id"=>$cat_id])->find();
  719. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  720. //部分参数的大小校验
  721. $vali = Validate::rule([
  722. 'expire_day|有效时长'=>'require|elt:214748364',
  723. 'delivery_day|物流时长'=>'require|elt:214748364',
  724. 'work_day|生产工期'=>'require|elt:214748364',
  725. 'weight|总重量'=>'require|max:10',
  726. ]);
  727. $temp = [
  728. 'expire_day'=>$expire_day,
  729. 'delivery_day'=>$delivery_day,
  730. 'work_day'=>$work_day,
  731. 'weight'=>$weight,
  732. ];
  733. if(!$vali->check($temp)) return error_show(0,$vali->getError());
  734. $sale_cost_fee = $cost_fee;//销售工艺费默认取传值
  735. $cat_top_list = made($cat_id);
  736. $cat_top_id = isset($cat_top_list[0]['id']) ? $cat_top_list[0]['id'] : 0;
  737. if ($is_gold_price == 1 && $cat_top_id == 6) {
  738. $gold = Db::name("gold_price1")->where(["type"=>$metal_id,"is_del"=>0,"status"=>1])->order("addtime desc")
  739. ->find();
  740. //$total_fee = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee*$weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  741. //$total_fee(成本合计初始价格) =打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价0+运费;
  742. $total_fee = $demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $good_weight * $gold["price"] + $cost_fee * $good_weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee;
  743. // $saleprice = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee/(1-$budget)* $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  744. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  745. // $saleprice = ($open_fee / $zxinfo['num'] + $weight * $gold["price"] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee) / (1 - $budget);
  746. $saleprice = $total_fee/ (1 - $budget);
  747. //销售工艺费=((开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100)-(打样费/购买数量 + 开模费/购买数量 +包装费+加标费+证书费+产品裸价0+运费) )/商品重量-最新金价
  748. $sale_cost_fee = ($saleprice - ($demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee)) /$good_weight - $gold["price"];
  749. }else{
  750. if($nake_fee){
  751. $saleprice = ($demo_fee / $zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee * $good_weight +
  752. $pakge_fee + $mark_fee + $cert_fee +$nake_fee)/ (1 - $budget);
  753. $total_fee = $demo_fee / $zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee *$good_weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee;
  754. }else{
  755. $saleprice = ($demo_fee/$zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee * $good_weight + $pakge_fee + $mark_fee + $cert_fee) /
  756. (1 - $budget);
  757. $total_fee = $demo_fee/$zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee *$good_weight + $pakge_fee + $mark_fee + $cert_fee;
  758. }
  759. }
  760. $supplier = Db::name('supplier')
  761. ->field('id,person,personid')
  762. ->where('code',$supplierNo)
  763. ->findOrEmpty();
  764. $data=[
  765. "bidNo"=>$bidNo,
  766. "infoNo"=>$infoNo,
  767. "zxNo"=>$zxinfo['zxNo'],
  768. "spuCode"=>$spucode,
  769. "good_name"=>$pname,
  770. "brand_id"=>$brandid,
  771. "cat_id"=>$cat_id,
  772. "specinfo"=>json_encode($specinfo),
  773. "unit_id"=>$unit_id,
  774. "cost_desc"=>$cost_desc,
  775. "work_day"=>$work_day,
  776. "delivery_day"=>$delivery_day,
  777. "good_img"=>is_array($good_img)?implode(',',$good_img):$good_img,
  778. "expire_day"=>$expire_day,
  779. "origin_place"=>$origin_place,
  780. "supplierNo"=>$supplierNo,
  781. "pay_way"=>$pay_way,
  782. "tax"=>$tax,
  783. "send_way"=>$send_way,
  784. "metal_id"=>$metal_id,
  785. "is_gold_price"=>$is_gold_price,
  786. "config"=>$config,
  787. "other_config"=>$other_config,
  788. "weight"=>$weight,
  789. "good_weight"=>$good_weight,
  790. "gold_price"=>isset($gold["price"])?$gold["price"]:0,
  791. "is_diff"=>$is_diff,
  792. "demo_fee"=>$demo_fee,
  793. "delivery_fee"=>$delivery_fee,
  794. "open_fee"=>$open_fee,
  795. "pakge_fee"=>$pakge_fee,
  796. "nake_fee"=>$nake_fee,
  797. "mark_fee"=>$mark_fee,
  798. "cert_fee"=>$cert_fee,
  799. "cost_fee"=>$cost_fee,
  800. "total_fee"=>$total_fee,
  801. "supply_area"=>$supply_area,
  802. "remark"=>$remark,
  803. "sale_price"=>$saleprice,
  804. "sale_cost_fee"=>$sale_cost_fee,
  805. "origin_cost_fee"=>$sale_cost_fee,
  806. "origin_price"=>$saleprice,
  807. "createrid"=>$createrid,
  808. "creater"=>$creater,
  809. "status"=>$zxinfo['status']==1 ?1 :2,
  810. "is_del"=>0,
  811. "addtime"=>date("Y-m-d H:i:s"),
  812. "updatetime"=>date("Y-m-d H:i:s"),
  813. 'delivery_place'=>$delivery_place,//发货地
  814. 'cgder' => $supplier['person'] ?? '',
  815. 'cgderid' => $supplier['personid'] ?? 0,
  816. ];
  817. Db::startTrans();
  818. try{
  819. $insert= Db::name("consult_bids")->insert($data);
  820. if($insert){
  821. if($zx['is_project']==1 && $zx['projectNo']!="" && $zxinfo['pgNo']!=""){
  822. $projectinfo =Db::name("project_info")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"is_del"=>0])->find();
  823. if($projectinfo==false){
  824. Db::rollback();
  825. return error_show(1006,"未找到项目信息");
  826. }
  827. $temp=[];
  828. $temp['spuCode']=$spucode;
  829. $temp['skuCode']="";
  830. $temp['pgNo']=$zxinfo['pgNo'];
  831. $temp['projectNo']=$zx['projectNo'];
  832. $temp['good_name']=$pname;
  833. $temp['good_type']=$projectinfo['good_type'];
  834. $temp['data_source']=2;
  835. $temp['cat_id']=$cat_id;
  836. $temp['budget_price']=$projectinfo['budget_price'];
  837. $temp['sale_price']=$saleprice;
  838. $temp['origin_price']=$total_fee;
  839. $temp['num']=$zxinfo['num'];
  840. $temp['status']=0;
  841. $temp['is_del']=0;
  842. $temp['creater']=$creater;
  843. $temp['createrid']=$createrid;
  844. $temp['addtime']=date("Y-m-d H:i:s");
  845. $temp['updatetime']=date("Y-m-d H:i:s");
  846. $nu = Db::name("project_feedback")->insert($temp);
  847. if($nu==false){
  848. Db::rollback();
  849. return error_show(1006,"项目反馈失败");
  850. }else{
  851. $old_projectinfo_status = $projectinfo['status'];
  852. $projectinfo['status']=2;
  853. $projectinfo['updatetime']=date("Y-m-d H:i:s");
  854. $up = Db::name("project_info")->save($projectinfo);
  855. if($up){
  856. //修改状态,添加待办,只记录动作
  857. ActionLog::logAdd($this->post['token'], [
  858. "order_code" => $projectinfo['pgNo'],//编码
  859. "status" => $old_projectinfo_status,//这里的status是之前的值
  860. "action_remark" => '',//备注
  861. "action_type" => "status"//新建create,编辑edit,更改状态status
  862. ], "PRI", 2, $projectinfo);
  863. $count = Db::name("project_info")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])
  864. ->count();
  865. if($count==0){
  866. $projetc =Db::name("project")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])->find();
  867. if($projetc!=false){
  868. $proc =Db::name("project")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])->save
  869. (["status"=>2,"updatetime"=>date("Y-m-d H:i:s")]);
  870. if($proc==false){
  871. Db::rollback();
  872. return error_show(1006,"项目反馈失败");
  873. }else{
  874. //修改状态,添加待办
  875. ActionLog::logAdd($this->post['token'], [
  876. "order_code" => $projetc['projectNo'],//项目编码
  877. "status" => 1,//这里的status是之前的值
  878. "action_remark" => '',//备注
  879. "action_type" => "status"//新建create,编辑edit,更改状态status
  880. ], "PRO", 2, $projetc);
  881. ProcessOrder::AddProcess($this->post['token'], [
  882. "order_type" => 'PRO',
  883. "order_code" => $projetc['projectNo'],
  884. "order_id" => $projetc['id'],
  885. "order_status" => 2,"before_status"=>1
  886. ]);
  887. }
  888. }
  889. }
  890. }
  891. }
  892. }
  893. Db::commit();
  894. return app_show(0,"反馈成功",["bidNo"=>$bidNo]);
  895. }else{
  896. Db::rollback();
  897. return error_show(1006,"反馈失败");
  898. }
  899. }catch (\Exception $e){
  900. Db::rollback();
  901. return error_show(1006,$e->getMessage());
  902. }
  903. }
  904. //反馈商品详情
  905. public function feadinfo(){
  906. $bidNo =isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  907. if($bidNo==""){
  908. return error_show(1004,"参数bidNo不能为空");
  909. }
  910. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  911. if($info==false){
  912. return error_show(1004,"未找到商品数据");
  913. }
  914. $unit =Db::name("unit")->where(["id"=>$info['unit_id']])->find();
  915. $info['unit'] = isset($unit['unit'])?$unit['unit']:'';
  916. $info['cat_info'] = made($info['cat_id'],[]);
  917. $info['noble_weight'] = $info['good_weight'];
  918. $supplier = Db::name("supplier")->where(["code"=>$info['supplierNo']])->find();
  919. $info['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  920. if($info['brand_id']!=0){
  921. $brand=Db::name("brand")->where(["id"=>$info['brand_id']])->find();
  922. $info["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  923. }else{
  924. $info["brand_name"]="";
  925. $info["brand_id"]="";
  926. }
  927. $catinfo = Db::name("cat")->where(["id"=>$info['cat_id']])->find();
  928. $bidinfo = Db::name("consult_info")->where(["infoNo"=>$info["infoNo"]])->find();
  929. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  930. $god=[
  931. "metal_id"=>$info['metal_id'],
  932. "weight"=>$info["good_weight"],
  933. "demo_fee"=>$info["demo_fee"],
  934. "delivery_fee"=>$info["delivery_fee"],
  935. "open_fee"=>$info["open_fee"],
  936. "packing_fee"=>$info["pakge_fee"],
  937. "mark_fee"=>$info["mark_fee"],
  938. "nake_fee"=>$info["nake_fee"],
  939. "cert_fee"=>$info["cert_fee"],
  940. "cost_fee"=>$info["cost_fee"],
  941. "num"=>$bidinfo["num"],
  942. ];
  943. if($info['is_gold_price']==1){
  944. $price = GoldPrice($god, $budget/100);
  945. $info['sale_price'] =round($price,2);
  946. }
  947. $info['specinfo'] = json_decode($info['specinfo'],true);
  948. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  949. if($info['delivery_place']!=""){
  950. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$info['delivery_place']);
  951. }
  952. $info['delivery_place_cn']=GetAddr(json_encode($place));
  953. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  954. if($info['origin_place']!=""){
  955. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$info['origin_place']);
  956. }
  957. $info['origin_place_cn']=GetAddr(json_encode($place));
  958. $info['metal_name']=isset($info['metal_id'])&& $info['metal_id']!=0?$this->noble[$info['metal_id']]:"";
  959. $bargain =Db::name("bargain_order")->where(['bidsNo'=>$bidNo,"is_del"=>0])->find();
  960. $info['bargain'] =$bargain;
  961. $info['good_img'] = explode(',',$info['good_img']);
  962. //添加商品创建人字段
  963. $good_info = Db::name('good_basic')
  964. ->field('id,createrid,creater')
  965. ->where('is_del',0)
  966. ->where('spuCode',$info['spuCode'])
  967. ->findOrEmpty();
  968. $info['good_createrid'] = $good_info['createrid']??0;
  969. $info['good_creater'] = $good_info['creater']??'';
  970. return app_show(0,"获取成功",$info);
  971. }
  972. //反馈商品编辑
  973. public function feededit(){
  974. $bidNo= isset($this->post['bidNo'])&&$this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  975. if($bidNo==""){
  976. return error_show(1002,"参数bidNo不能为空");
  977. }
  978. $bidinfo = Db::name("consult_bids")->where(["bidNo"=>$bidNo,"is_del"=>0])->find();
  979. if($bidinfo==false){
  980. return error_show(1003,"未找到信息数据");
  981. }
  982. if($bidinfo['status']>=5){
  983. return error_show(1004,"咨询单已确认无法修改");
  984. }
  985. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$bidinfo['infoNo'],"is_del"=>0])->find();
  986. if($zxinfo==false){
  987. return error_show(1003,"未找到信息数据");
  988. }
  989. $zx = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo'],"is_del"=>0])->find();
  990. if($zx==false){
  991. return error_show(1003,"未找咨询信息数据");
  992. }
  993. $pname = isset($this->post['pname'])&&$this->post['pname']!=""? trim($this->post['pname']):"";
  994. if($pname==""){
  995. return error_show(1002,"参数pname不能为空");
  996. }
  997. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"";
  998. // if($brandid==""){
  999. // return error_show(1002,"参数brandid不能为空");
  1000. // }
  1001. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? trim($this->post['cat_id']):"";
  1002. if($cat_id==""){
  1003. return error_show(1002,"参数cat_id不能为空");
  1004. }
  1005. $specin= isset($this->post['specinfo'])&&!empty($this->post['specinfo'])?$this->post['specinfo']:"";
  1006. if($specin==""){
  1007. return error_show(1003,"参数specinfo不能为空");
  1008. }
  1009. $specinfo=[];
  1010. foreach ($specin as $v){
  1011. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  1012. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  1013. $v['spec_name']=isset($spec['spec_name'])?$spec['spec_name']:"";
  1014. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"";
  1015. $specinfo[]=$v;
  1016. }
  1017. $unit_id = isset($this->post['unit_id'])&&$this->post['unit_id']!=""? intval($this->post['unit_id']):"";
  1018. $cost_desc = isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""? trim($this->post['cost_desc']):"";
  1019. $work_day = isset($this->post['work_day'])&&$this->post['work_day']!=""? intval($this->post['work_day']):"";
  1020. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!=""? intval($this->post['delivery_day']):"";
  1021. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""? $this->post['good_img']:[];
  1022. $expire_day = isset($this->post['expire_day'])&&$this->post['expire_day']!=""? intval($this->post['expire_day'])
  1023. :"";
  1024. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!=""? trim($this->post['origin_place']):"";
  1025. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
  1026. $pay_way = isset($this->post['pay_way'])&&$this->post['pay_way']!=""? intval($this->post['pay_way']):"";
  1027. $tax = isset($this->post['tax'])&&$this->post['tax']!=""? trim($this->post['tax']):"";
  1028. $send_way = isset($this->post['send_way'])&&$this->post['send_way']!=""? intval($this->post['send_way']):"0";
  1029. $metal_id = isset($this->post['metal_id'])&&$this->post['metal_id']!=""? intval($this->post['metal_id']):"0";
  1030. $is_gold_price = isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!=""? intval($this->post['is_gold_price']):"0";
  1031. $config = isset($this->post['config'])&&$this->post['config']!=""? $this->post['config']:"";
  1032. $other_config = isset($this->post['other_config'])&&$this->post['other_config']!=""? $this->post['other_config']:"";
  1033. $weight = isset($this->post['weight'])&&$this->post['weight']!=""? floatval($this->post['weight']):"0";
  1034. $noble_weight = isset($this->post['noble_weight'])&&$this->post['noble_weight']!=""? floatval($this->post['noble_weight']):"0";
  1035. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!=""? floatval($this->post['demo_fee']):"0";
  1036. $delivery_fee = isset($this->post['delivery_fee'])&&$this->post['delivery_fee']!=""? floatval($this->post['delivery_fee']):"0";
  1037. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!=""? floatval($this->post['open_fee']):"0";
  1038. $pakge_fee = isset($this->post['pakge_fee'])&&$this->post['pakge_fee']!=""? floatval($this->post['pakge_fee']):"0";
  1039. $nake_fee = isset($this->post['nake_fee'])&&$this->post['nake_fee']!==""? floatval($this->post['nake_fee']):0;
  1040. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!=""? floatval($this->post['mark_fee']):"0";
  1041. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!=""? floatval($this->post['cert_fee']):"0";
  1042. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!=""? floatval($this->post['cost_fee']):"0";
  1043. $is_diff = isset($this->post['is_diff'])&&$this->post['is_diff']!==""? intval($this->post['is_diff']):"";
  1044. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  1045. $remark = isset($this->post['remark'])&&$this->post['remark']!=""? trim($this->post['remark']):"";
  1046. $delivery_place = isset($this->post['delivery_place'])&& $this->post['delivery_place']!='' ? trim($this->post['delivery_place']):"";
  1047. if($delivery_place==''){
  1048. return error_show(1002,"参数delivery_place不能为空");
  1049. }
  1050. $catinfo = Db::name("cat")->where(["id"=>$cat_id])->find();
  1051. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  1052. $sale_cost_fee = $bidinfo['sale_cost_fee'];
  1053. $cat_top_list = made($cat_id);
  1054. $cat_top_id = isset($cat_top_list[0]['id']) ? $cat_top_list[0]['id'] : 0;
  1055. if ($is_gold_price == 1 && $cat_top_id == 6) {
  1056. $gold = Db::name("gold_price1")->where(["type"=>$metal_id,"is_del"=>0,"status"=>1])->order("addtime desc")
  1057. ->find();
  1058. //$total_fee(成本合计初始价格) =打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价0+运费;
  1059. $total_fee = $demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $noble_weight * $gold["price"] + $cost_fee * $noble_weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee;
  1060. // $saleprice = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee/(1-$budget)* $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  1061. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  1062. $saleprice = $total_fee / (1 - $budget);
  1063. //销售工艺费=((开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100)-(打样费/购买数量 + 开模费/购买数量 +包装费+加标费+证书费+产品裸价0+运费) )/商品重量-最新金价
  1064. $sale_cost_fee = ( $saleprice- ($demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee)) / $noble_weight - $gold["price"];
  1065. }else{
  1066. $saleprice = ($demo_fee / $zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee*$noble_weight + $pakge_fee +
  1067. $mark_fee + $cert_fee + $nake_fee) / (1 - $budget);
  1068. $total_fee = $demo_fee/$zxinfo['num']+$delivery_fee+$open_fee/$zxinfo['num'] + $cost_fee * $noble_weight + $pakge_fee + $mark_fee+$cert_fee +$nake_fee;
  1069. }
  1070. Db::startTrans();
  1071. try{
  1072. $data=[
  1073. "good_name"=>$pname,
  1074. "brand_id"=>$brandid,
  1075. "cat_id"=>$cat_id,
  1076. "specinfo"=>json_encode($specinfo),
  1077. // "material"=>$material,
  1078. "unit_id"=>$unit_id,
  1079. "cost_desc"=>$cost_desc,
  1080. "work_day"=>$work_day,
  1081. "delivery_day"=>$delivery_day,
  1082. "good_img"=>is_array($good_img)?implode(',',$good_img):$good_img,
  1083. "expire_day"=>$expire_day,
  1084. "origin_place"=>$origin_place,
  1085. "supplierNo"=>$supplierNo,
  1086. "pay_way"=>$pay_way,
  1087. "tax"=>$tax,
  1088. "send_way"=>$send_way,
  1089. "metal_id"=>$metal_id,
  1090. "is_gold_price"=>$is_gold_price,
  1091. "config"=>$config,
  1092. "other_config"=>$other_config,
  1093. "weight"=>$weight,
  1094. "good_weight"=>$noble_weight,
  1095. "is_diff"=>$is_diff,
  1096. "demo_fee"=>$demo_fee,
  1097. "gold_price"=>isset($gold["price"])?$gold["price"]:0,
  1098. "delivery_fee"=>$delivery_fee,
  1099. "open_fee"=>$open_fee,
  1100. "pakge_fee"=>$pakge_fee,
  1101. "nake_fee"=>$nake_fee,
  1102. "mark_fee"=>$mark_fee,
  1103. "cert_fee"=>$cert_fee,
  1104. "cost_fee"=>$cost_fee,
  1105. "sale_cost_fee"=>$sale_cost_fee,
  1106. "origin_cost_fee"=>$sale_cost_fee,
  1107. "total_fee"=>$total_fee,
  1108. "sale_price"=>$saleprice,
  1109. "origin_price"=>$saleprice,
  1110. "supply_area"=>$supply_area,
  1111. "remark"=>$remark,
  1112. "status"=>0,
  1113. "updatetime"=>date("Y-m-d H:i:s"),
  1114. 'delivery_place' => $delivery_place
  1115. ];
  1116. $insert= Db::name("consult_bids")->where($bidinfo)->save($data);
  1117. if($insert){
  1118. if($zxinfo['bargain_status']==1){
  1119. $zxinfo['bargain_status']=0;
  1120. $infoip =Db::name("consult_info")->save($zxinfo);
  1121. if($infoip==false){
  1122. Db::rollback();
  1123. return error_show(1006,"咨询信息状态更新失败");
  1124. }
  1125. }
  1126. if($zx['is_project']==1 && $zx['projectNo']!="" && $zxinfo['pgNo']!=""){
  1127. $projectinfo =Db::name("project_info")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"is_del"=>0])->find();
  1128. if($projectinfo==false){
  1129. Db::rollback();
  1130. return error_show(1006,"未找到项目信息");
  1131. }
  1132. $feed = Db::name("project_feedback")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"spuCode"=>$bidinfo['spuCode'],"is_del"=>0])->find();
  1133. if($feed!=false) {
  1134. $feed['good_name']=$pname;
  1135. $feed['good_type']=$projectinfo['good_type'];
  1136. $feed['cat_id']=$cat_id;
  1137. $feed['sale_price']=$saleprice;
  1138. $feed['origin_price']=$total_fee;
  1139. $feed['updatetime']=date("Y-m-d H:i:s");
  1140. $temp['updatetime']=date("Y-m-d H:i:s");
  1141. $nu=Db::name("project_feedback")->save($feed);
  1142. if ($nu == false) {
  1143. Db::rollback();
  1144. return error_show(1006 , "项目反馈失败");
  1145. } else {
  1146. $old_projectinfo_status=$projectinfo['status'];
  1147. $projectinfo['status']=2;
  1148. $projectinfo['updatetime']=date("Y-m-d H:i:s");
  1149. $up=Db::name("project_info")->save($projectinfo);
  1150. if ($up) {
  1151. //修改状态,添加待办,只记录动作
  1152. ActionLog::logAdd($this->post['token'] , [
  1153. "order_code"=>$projectinfo['pgNo'] ,//编码
  1154. "status"=>$old_projectinfo_status ,//这里的status是之前的值
  1155. "action_remark"=>'' ,//备注
  1156. "action_type"=>"status"//新建create,编辑edit,更改状态status
  1157. ] , "PRI" , 2 , $projectinfo
  1158. );
  1159. $count=Db::name("project_info")->where(["projectNo"=>$projectinfo['projectNo'] , "status"=>1])->count();
  1160. if ($count == 0) {
  1161. //先查询是否存在status==1的项目,有的话再更新,否则跳过
  1162. $project_id=Db::name("project")->where(["projectNo"=>$projectinfo['projectNo'] , "status"=>1])->value('id' , 0);
  1163. if ($project_id) {
  1164. $proc=Db::name("project")->where(["id"=>$project_id])->update(["status"=>2 , "updatetime"=>date("Y-m-d H:i:s")]);
  1165. if ($proc == false) {
  1166. Db::rollback();
  1167. return error_show(1006 , "项目反馈失败");
  1168. } else {
  1169. //修改状态,添加待办
  1170. ActionLog::logAdd($this->post['token'] , [
  1171. "order_code"=>$projectinfo['projectNo'] ,//项目编码
  1172. "status"=>1 ,//这里的status是之前的值
  1173. "action_remark"=>'' ,//备注
  1174. "action_type"=>"status"//新建create,编辑edit,更改状态status
  1175. ] , "PRO" , 2 , $this->post
  1176. );
  1177. ProcessOrder::AddProcess($this->post['token'] , [
  1178. "order_type"=>'PRO' ,
  1179. "order_code"=>$projectinfo['projectNo'] ,
  1180. "order_id"=>$project_id ,
  1181. "order_status"=>2 , "before_status"=>1
  1182. ]
  1183. );
  1184. }
  1185. }
  1186. }
  1187. }
  1188. }
  1189. }
  1190. }
  1191. Db::commit();
  1192. return app_show(0,"编辑成功");
  1193. }else{
  1194. Db::rollback();
  1195. return error_show(1004,"编辑失败");
  1196. }
  1197. }catch (\Exception $e){
  1198. Db::rollback();
  1199. return error_show(1004,$e->getMessage());
  1200. }
  1201. }
  1202. //生成议价单
  1203. public function bargain_add(){
  1204. $bidNo = isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  1205. if($bidNo===""){
  1206. return error_show(1004,"参数bidNo不能为空");
  1207. }
  1208. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  1209. if($info==false){
  1210. return error_show(1004,"未找到商品数据");
  1211. }
  1212. $consult =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
  1213. if($consult==false){
  1214. return error_show(1004,"未找到咨询数据");
  1215. }
  1216. $bargain_price = isset($this->post['bargain_price'])&& $this->post['bargain_price']!=""?floatval($this->post['bargain_price']):"";
  1217. if($bargain_price===""){
  1218. return error_show(1004,"参数bargain_price不能为空");
  1219. }
  1220. $cost_price = isset($this->post['cost_price'])&& $this->post['cost_price']!=""?floatval($this->post['cost_price']):"";
  1221. if($info['is_gold_price']==1){
  1222. if($cost_price==""){
  1223. return error_show(1004,"参数cost_price不能为空");
  1224. }
  1225. $catinfo = Db::name("cat")->where(["id"=>$info['cat_id']])->find();
  1226. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  1227. $gold = Db::name("gold_price1")->where(["type"=>$info['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1228. ->find();
  1229. $bargain_price = ($info['demo_fee']/$consult['num']+$info['delivery_fee']+$info['open_fee']/$consult['num']+$info['good_weight'] * $gold["price"] + $cost_price *$info['good_weight']+$info['pakge_fee']+$info['mark_fee'] +$info['cert_fee'] +$info['nake_fee']) / (1 - $budget);
  1230. }
  1231. $bargain_reason = isset($this->post['bargain_reason'])&& $this->post['bargain_reason']!=""?trim($this->post['bargain_reason']):"";
  1232. // if($bargain_reason===""){
  1233. // return error_show(1004,"参数bargain_reason不能为空");
  1234. // }
  1235. $infos =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
  1236. if($infos==false){
  1237. return error_show(1004,"未找到商品数据");
  1238. }
  1239. if($infos['status']!=2&&$infos['status']!=3&&$infos['status']!=7){
  1240. return error_show(1004,"咨询单招标未结束或已确认商品");
  1241. }
  1242. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1243. if($token==''){
  1244. return error_show(105,"参数token不能为空");
  1245. }
  1246. $user =GetUserInfo($token);
  1247. if(empty($user)||$user['code']!=0){
  1248. return error_show(1002,"用户数据不存在");
  1249. }
  1250. //新增两个字段
  1251. //议价备注
  1252. $bargain_remark = isset($this->post['bargain_remark']) && $this->post['bargain_remark'] != "" ? trim($this->post['bargain_remark']) : "";
  1253. //议价原因id
  1254. $result_info_id = isset($this->post['result_info_id']) && $this->post['result_info_id'] != "" ? $this->post['result_info_id'] : "";
  1255. if ($result_info_id != '') {
  1256. $temp = Db::name('result_info')->field('id')->where(['result_code' => $result_info_id, 'type' => 7, 'status' => 1, 'is_del' => 0])->find();//type 7议价原因
  1257. if (empty($temp)) return error_show(1004, "议价原因选择不正确");
  1258. }
  1259. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1260. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1261. $bargainNo =makeNo("BA");
  1262. Db::startTrans();//::todo 金价 毛利计算
  1263. try{
  1264. $data=[
  1265. "bidsNo"=>$bidNo,
  1266. "infoNo"=>$info['infoNo'],
  1267. "zxNo"=>$info['zxNo'],
  1268. "bargainNo"=>$bargainNo,
  1269. "bargain_type"=>1,
  1270. "bargain_reason"=>$bargain_reason,
  1271. "sale_price"=>$info['sale_price'],
  1272. "cost_before_price"=>$info['sale_cost_fee'],
  1273. "cost_after_price"=>$cost_price,
  1274. "before_rate"=>round(($info['origin_price']-$info['total_fee'])/$info['origin_price'],2),
  1275. "after_rate"=>round(($bargain_price-$info['total_fee'])/$bargain_price,2),
  1276. "after_price"=>$bargain_price,
  1277. "exam_info"=>"",
  1278. "status"=>0,
  1279. "is_del"=>0,
  1280. "creater"=>$creater,
  1281. "createrid"=>$createrid,
  1282. "addtime"=>date("Y-m-d H:i:s"),
  1283. "updatetime"=>date("Y-m-d H:i:s"),
  1284. 'bargain_remark'=>$bargain_remark,
  1285. 'result_info_id'=>$result_info_id,
  1286. ];
  1287. $int = Db::name("bargain_order")->insertGetId($data);
  1288. if($int){
  1289. //修改状态,添加待办
  1290. ActionLog::logAdd($this->post['token'], [
  1291. "order_code" => $bargainNo,//咨询单详情编号
  1292. "status" => 0,//这里的status是之前的值
  1293. "action_remark" => '',//备注
  1294. "action_type" => "status"//新建create,编辑edit,更改状态status
  1295. ], "YJD", $data['status'], $data);
  1296. ProcessOrder::AddProcess($this->post['token'], [
  1297. "order_type" => 'YJD',
  1298. "order_code" => $bargainNo,
  1299. "order_id" => $int,
  1300. "order_status" =>0,
  1301. "before_status"=>0
  1302. ]);
  1303. $odlstatus=$info['status'];
  1304. $info['status']=3;
  1305. $info['updatetime']=date("Y-m-d H:i:s");
  1306. $up =Db::name("consult_bids")->save($info);
  1307. if($up){
  1308. //修改状态,添加待办
  1309. ActionLog::logAdd($this->post['token'], [
  1310. "order_code" => $bidNo,//咨询单详情编号
  1311. "status" => $odlstatus,//这里的status是之前的值
  1312. "action_remark" => '',//备注
  1313. "action_type" => "status"//新建create,编辑edit,更改状态status
  1314. ], "FKD", $info['status'], $info);
  1315. $old_infos_status = $infos['status'];
  1316. $infos['status']=3;
  1317. $infos['updatetime']=date("Y-m-d H:i:s");
  1318. $ups =Db::name("consult_info")->save($infos);
  1319. if($ups){
  1320. //修改状态,添加待办
  1321. ActionLog::logAdd($this->post['token'], [
  1322. "order_code" => $infos['infoNo'],//咨询单详情编号
  1323. "status" => $old_infos_status,//这里的status是之前的值
  1324. "action_remark" => '',//备注
  1325. "action_type" => "status"//新建create,编辑edit,更改状态status
  1326. ], "ZXD", $infos['status'], $infos);
  1327. //维护台账信息
  1328. Db::name('standing_book')->where('infoNo', $info['infoNo'])->update(['bargainNo' => $bargainNo,'updatetime' => date('Y-m-d H:i:s')]);
  1329. Db::commit();
  1330. return app_show(0,"议价单生成成功",["bargainNo"=>$bargainNo]);
  1331. }
  1332. }
  1333. }
  1334. Db::rollback();
  1335. return error_show(1004,"议价单新建失败");
  1336. }catch (\Exception $e){
  1337. Db::rollback();
  1338. return error_show(1004,$e->getMessage());
  1339. }
  1340. }
  1341. //选择商品
  1342. public function bids_check(){
  1343. $bidNo = isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  1344. if($bidNo===""){
  1345. return error_show(1004,"参数bidNo不能为空");
  1346. }
  1347. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  1348. if($info==false){
  1349. return error_show(1004,"未找到商品数据");
  1350. }
  1351. $infos =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
  1352. if($infos==false){
  1353. return error_show(1004,"未找到商品数据");
  1354. }
  1355. if($infos['status']!=2&&$infos['status']!=3&&$infos['status']!=7){
  1356. return error_show(1004,"咨询单招标未结束或已确认商品");
  1357. }
  1358. Db::startTrans();
  1359. try {
  1360. $oldstattus=$info['status'];
  1361. $info['status']=6;
  1362. $info['updatetime']=date("Y-m-d H:i:s");
  1363. $bids = Db::name("consult_bids")->save($info);
  1364. if($bids){
  1365. //修改状态,添加待办
  1366. ActionLog::logAdd($this->post['token'], [
  1367. "order_code" =>$bidNo,//咨询单详情编号
  1368. "status" => $oldstattus,//这里的status是之前的值
  1369. "action_remark" => '',//备注
  1370. "action_type" => "status"//新建create,编辑edit,更改状态status
  1371. ], "FKD", $info['status'], $info);
  1372. $old_infos_status = $infos['status'];
  1373. $infos['status']=4;
  1374. $infos['updatetime']=date("Y-m-d H:i:s");
  1375. $se = Db::name("consult_info")->save($infos);
  1376. if($se){
  1377. //修改状态,添加待办
  1378. ActionLog::logAdd($this->post['token'], [
  1379. "order_code" => $infos['infoNo'],//咨询单详情编号
  1380. "status" => $old_infos_status,//这里的status是之前的值
  1381. "action_remark" => '',//备注
  1382. "action_type" => "status"//新建create,编辑edit,更改状态status
  1383. ], "ZXD", $infos['status'], $infos);
  1384. Db::name("bargain_order")->where(["bidsNo"=>$bidNo,"is_del"=>0,"status"=>[0,2,4,5,7]])
  1385. ->update(['status'=>12,"remark"=>'已选择商品,取消议价',"updatetime"=>date("Y-m-d H:i:s")]);
  1386. Db::commit();
  1387. return app_show(0,"商品确定成功");
  1388. }
  1389. }
  1390. Db::rollback();
  1391. return error_show(1004,"商品确认失败");
  1392. }catch (\Exception $e){
  1393. Db::rollback();
  1394. return error_show(1004,$e->getMessage());
  1395. }
  1396. }
  1397. //议价审核
  1398. /**
  1399. * status:
  1400. * 0待审核 1业务主管审核通过 2 业务税率未通过 3 业务驳回 4 专员通过 5 专员驳回 6 财务通过 7 财务税率未通过 8财务驳回 9 boss通过 10 boss 税率越线通过 11 驳回
  1401. */
  1402. public function bargain_status(){
  1403. $bargainNo = isset($this->post['bargainNo'])&& $this->post['bargainNo']!=""?trim($this->post['bargainNo']):"";
  1404. if($bargainNo===""){
  1405. return error_show(1004,"参数bargainNo不能为空");
  1406. }
  1407. $info =Db::name("bargain_order")->where(['bargainNo'=>$bargainNo,"is_del"=>0])->find();
  1408. if($info==false){
  1409. return error_show(1004,"未找到议价数据");
  1410. }
  1411. if($info['status']==12){
  1412. return error_show(1004,"议价单已取消");
  1413. }
  1414. $bids=Db::name("consult_bids")->where(["bidNo"=>$info["bidsNo"],"is_del"=>0])->find();
  1415. if($bids==false){
  1416. return error_show(1004,"未找到商品数据");
  1417. }
  1418. $coninfo=Db::name("consult_info")->where(["infoNo"=>$bids["infoNo"],"is_del"=>0])->find();
  1419. if($coninfo==false){
  1420. return error_show(1004,"未找到咨询单数据");
  1421. }
  1422. if($bids['status']==6){
  1423. return error_show(1004,"咨询已选择商品");
  1424. }
  1425. $status = isset($this->post['status'])&& $this->post['status']!=='' ? intval($this->post['status']):"";
  1426. if($status===''){
  1427. return error_show(1005,"参数status不能为空");
  1428. }
  1429. $catinfo = Db::name("cat")->where(["id"=>$bids['cat_id']])->find();
  1430. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  1431. $rate = isset($catinfo['rate']) ? $catinfo['rate']/100:0; //业务主管利率
  1432. $money_rate = isset($catinfo['money_rate']) ? $catinfo['money_rate']/100:0;//财务主管利率
  1433. $lower_rate = isset($catinfo['lower_rate']) ? $catinfo['lower_rate']/100:0;//boss主管利率
  1434. if($bids['is_gold_price']==1){
  1435. $gold = Db::name("gold_price1")->where(["type"=>$bids['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1436. ->find();
  1437. // $saleprice = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee/(1-$budget)* $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  1438. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  1439. $total_fe= $bids['demo_fee'] / $coninfo['num']+$bids['delivery_fee']+$bids['open_fee'] / $coninfo['num'] +
  1440. $bids['good_weight']*$gold["price"] +$bids['cost_fee']*$bids['good_weight'] + $bids['pakge_fee'] +$bids['mark_fee'] + $bids['cert_fee'] + $bids['nake_fee'];
  1441. $saleprice =$total_fe / (1 - $budget);
  1442. $rate_price = $total_fe / (1 - $rate);
  1443. $money_price =$total_fe / (1 - $money_rate);
  1444. $lower_price =$total_fe / (1 - $lower_rate);
  1445. }else{
  1446. $total_fe= $bids['demo_fee']/$coninfo['num']+$bids['delivery_fee']+$bids['open_fee'] /
  1447. $coninfo['num']+$bids['cost_fee']*$bids['good_weight']+$bids['pakge_fee'] +$bids['mark_fee']+ $bids['cert_fee'] + $bids['nake_fee'];
  1448. if($bids['nake_fee']!=0){
  1449. $saleprice = ($total_fe)/ (1 - $budget);
  1450. $rate_price = ($total_fe)/ (1 - $rate);
  1451. $money_price =($total_fe)/ (1 - $money_rate);
  1452. $lower_price = ($total_fe) / (1 - $lower_rate);
  1453. }else{
  1454. $saleprice = $total_fe / (1 - $budget);
  1455. $rate_price =$total_fe/ (1 - $rate);
  1456. $money_price =$total_fe / (1 - $money_rate);
  1457. $lower_price = $total_fe/ (1 - $lower_rate);
  1458. }
  1459. }
  1460. $ra_status = $info['status'];
  1461. if($status==1){
  1462. if($info['status']==0){
  1463. if($info['after_price']<$rate_price){
  1464. $info['status']=2;
  1465. }else{
  1466. $info['status']=1;
  1467. }
  1468. }elseif($info['status']==2){
  1469. $info['status']=4;
  1470. }elseif($info['status']==4||$info['status']==5){
  1471. if($info['after_price']<$money_price){
  1472. $info['status']=7;
  1473. }else{
  1474. $info['status']=6;
  1475. }
  1476. }elseif($info['status']==7){
  1477. $info['lower_price'] =$lower_price;
  1478. if($info['after_price']<$lower_price){
  1479. $info['status']=10;
  1480. }else{
  1481. $info['status']=9;
  1482. }
  1483. }
  1484. }else{
  1485. if($info['status']==0){
  1486. $info['status']=3;
  1487. }elseif($info['status']==2){
  1488. $info['status']=4;
  1489. }elseif($info['status']==4||$info['status']==5){
  1490. $info['status']=8;
  1491. }elseif($info['status']==7){
  1492. $info['lower_price'] =$lower_price;
  1493. $info['status']=11;
  1494. }
  1495. }
  1496. $remark = isset($this->post['remark'])&& $this->post['remark']!=""?trim($this->post['remark']):"";
  1497. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1498. if($token==''){
  1499. return error_show(105,"参数token不能为空");
  1500. }
  1501. $user =GetUserInfo($token);
  1502. if(empty($user)||$user['code']!=0){
  1503. return error_show(1002,"用户数据不存在");
  1504. }
  1505. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1506. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1507. Db::startTrans();
  1508. try{
  1509. $examinfo = isset($info['exam_info'])&&$info['exam_info']!="" ? json_decode($info['exam_info'],true):[];
  1510. $examinfo[]=["status"=>$status,"info_status"=>$ra_status,"remark"=>$remark,"createrid"=>$createrid,
  1511. "creater"=>$creater];
  1512. // $info['status'] =$status;
  1513. $info['remark'] =$remark;
  1514. $info['exam_info']=json_encode($examinfo) ;
  1515. $info['updatetime'] =date("Y-m-d H:i:s");
  1516. $up =Db::name("bargain_order")->save($info);
  1517. if($up){
  1518. //修改状态,添加待办
  1519. ActionLog::logAdd($this->post['token'], [
  1520. "order_code" => $bargainNo,//咨询单详情编号
  1521. "status" =>$ra_status,//这里的status是之前的值
  1522. "action_remark" => '',//备注
  1523. "action_type" => "status"//新建create,编辑edit,更改状态status
  1524. ], "YJD", $info['status'], $info);
  1525. $process=["order_code"=>$bargainNo,"order_id"=>$info['id'],"order_status"=>$info['status'],"order_type"=>'YJD',"before_status"=>$ra_status];
  1526. ProcessOrder::AddProcess($token,$process);
  1527. if($info['status']==1||$info['status']==3||$info['status']==8||$info['status']==6||$info['status']==9||$info['status']==10||$info['status']==11){
  1528. $bidstatus=$bids['status'];
  1529. $bids['status']=5;
  1530. if($info['status']==1||$info['status']==6||$info['status']==9||$info['status']==10){
  1531. $bids['sale_price']=$info['after_price'];
  1532. if($bids['is_gold_price']==1){
  1533. // $gold = Db::name("gold_price1")->where(["type"=>$bids['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1534. // ->find();
  1535. // $bids['sale_price']= ($bids['open_fee'] / $coninfo['num'] + $bids['weight'] * $gold["price"] + $info['cost_after_price'] *$bids['weight'] +
  1536. // $bids['pakge_fee'] + $bids['mark_fee'] +$bids['cert_fee'] +$bids['nake_fee']) /(1 - $budget);
  1537. $bids['sale_cost_fee'] = $info['cost_after_price'];
  1538. $bids['gold_price'] =isset($gold["price"])?$gold["price"]:0;
  1539. }
  1540. }
  1541. $bids['updatetime']=date("Y-m-d H:i:s");
  1542. $up =Db::name("consult_bids")->save($bids);
  1543. if($up==false){
  1544. Db::rollback();
  1545. return error_show(1004,"数据更新失败");
  1546. }
  1547. ActionLog::logAdd($this->post['token'], [
  1548. "order_code" => $info["bidsNo"],//咨询单详情编号
  1549. "status" => $bidstatus,//这里的status是之前的值
  1550. "action_remark" => '',//备注
  1551. "action_type" => "status"//新建create,编辑edit,更改状态status
  1552. ], "FKD", $bids['status'], $bids);
  1553. }
  1554. Db::commit();
  1555. return app_show(0,"更新成功");
  1556. }
  1557. }catch (\Exception $e){
  1558. Db::rollback();
  1559. return error_show(1004,$e->getMessage());
  1560. }
  1561. }
  1562. public function bargain_info(){
  1563. $bargainNo = isset($this->post['bargainNo'])&& $this->post['bargainNo']!=""?trim($this->post['bargainNo']):"";
  1564. if($bargainNo===""){
  1565. return error_show(1004,"参数bargainNo不能为空");
  1566. }
  1567. $info =Db::name("bargain_order")->where(['bargainNo'=>$bargainNo,"is_del"=>0])->find();
  1568. if($info==false){
  1569. return error_show(1004,"未找到议价数据");
  1570. }
  1571. $bidinfos = Db::name("consult_bids")->where([["bidNo","=",$info['bidsNo']],["is_del","=",0]])->find();
  1572. if($bidinfos==false){
  1573. return error_show(1004,"未找到商品数据");
  1574. }
  1575. $consultinfos =Db::name("consult_info")->where([["infoNo","=",$bidinfos['infoNo']],["is_del","=",0]])->find();
  1576. if($consultinfos==false){
  1577. return error_show(1004,"未找到咨询商品数据");
  1578. }
  1579. $info['spuCode'] = isset($bidinfos['spuCode'])?$bidinfos['spuCode']:"";
  1580. $info['good_name'] = isset($bidinfos['good_name'])?$bidinfos['good_name']:"";
  1581. $info['good_img'] = isset($bidinfos['good_img'])?$bidinfos['good_img']:"";
  1582. $info['brand_id'] = isset($bidinfos['brand_id'])?$bidinfos['brand_id']:"";
  1583. $info['good_num'] = isset($consultinfos['num'])?$consultinfos['num']:"";
  1584. $info['before_rate'] =round($info['before_rate']*100,2);
  1585. $info['sale_price'] =round($bidinfos['origin_price'],2);
  1586. $info['cost_before_price'] =round($bidinfos['origin_cost_fee'],2);
  1587. $info['after_rate'] = round($info['after_rate']*100,2);
  1588. $info['exam_info'] = isset($info['exam_info'])&&$info['exam_info']!=""?json_decode($info['exam_info'],true):"";
  1589. if($bidinfos['brand_id']!=0){
  1590. $info['brand_id'] = $bidinfos['brand_id'];
  1591. $brand=Db::name("brand")->where(["id"=>$bidinfos['brand_id']])->find();
  1592. $info["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1593. }else{
  1594. $info["brand_name"]="";
  1595. $info["brand_id"]="";
  1596. }
  1597. $catinfo = Db::name("cat")->where(["id"=>$bidinfos['cat_id']])->find();
  1598. $info['can']= isset($bidinfos['cat_id']) && $bidinfos['cat_id'] !=0 ? made($bidinfos['cat_id']):[];
  1599. $unit =Db::name("unit")->where(["id"=>$bidinfos['unit_id']])->find();
  1600. $info['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1601. $bidinfoe = Db::name("consult_info")->where(["infoNo"=>$info["infoNo"]])->find();
  1602. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1603. $lower_rate = isset($catinfo['lower_rate']) ? $catinfo['lower_rate']/100:0;//boss主管利率
  1604. $info['budget'] =$budget;
  1605. $info['rate_status'] =0; //利率状态 0 业务主管利率无法通过 1 财务主管利率无法通过 2 boos利率无法通过 3 完全通过
  1606. if($info['after_rate']>=$catinfo['rate']){
  1607. //业务主管利率
  1608. $info['rate_status'] =1;
  1609. }
  1610. elseif ($info['after_rate']>=$catinfo['money_rate']){
  1611. //财务主管利率
  1612. $info['rate_status'] =2;
  1613. }
  1614. elseif ($info['after_rate']>=$catinfo['lower_rate']){
  1615. //boss利率
  1616. $info['rate_status'] =3;
  1617. }
  1618. $god=[
  1619. "metal_id"=>$bidinfos['metal_id'],
  1620. "weight"=>$bidinfos["good_weight"],
  1621. "demo_fee"=>$bidinfos["demo_fee"],
  1622. "delivery_fee"=>$bidinfos["delivery_fee"],
  1623. "open_fee"=>$bidinfos["open_fee"],
  1624. "packing_fee"=>$bidinfos["pakge_fee"],
  1625. "mark_fee"=>$bidinfos["mark_fee"],
  1626. "nake_fee"=>$bidinfos["nake_fee"],
  1627. "cert_fee"=>$bidinfos["cert_fee"],
  1628. "cost_fee"=>$bidinfos["cost_fee"],
  1629. "num"=>$bidinfoe["num"],
  1630. ];
  1631. $info['gold_price']=0;
  1632. $info['noble_weight']=$bidinfos['good_weight'];
  1633. if($bidinfos['is_gold_price']==1 &&$bidinfos['metal_id']>0){
  1634. $gold = Db::name("gold_price1")->where(["type"=>$bidinfos["metal_id"],"is_del"=>0,"status"=>1])->order("addtime desc")
  1635. ->find();
  1636. $info['gold_price'] =$gold['price'];
  1637. $lower_price = ($bidinfos['demo_fee']/$consultinfos['num']+$bidinfos['delivery_fee']+$bidinfos['open_fee']/$consultinfos['num'] + $bidinfos['good_weight']* $gold["price"] +$bidinfos['cost_fee']*$bidinfos['good_weight'] + $bidinfos['pakge_fee'] +$bidinfos['mark_fee'] + $bidinfos['cert_fee'] + $bidinfos['nake_fee']) / (1 - $lower_rate);
  1638. }else{
  1639. if($bidinfos['nake_fee']!=0){
  1640. $lower_price =($bidinfos['demo_fee']/$consultinfos['num']+$bidinfos['delivery_fee']+$bidinfos['open_fee']/$consultinfos['num']+$bidinfos['cost_fee']*$bidinfos['good_weight']+$bidinfos['pakge_fee'] +$bidinfos['mark_fee']+ $bidinfos['cert_fee'] + $bidinfos['nake_fee']) / (1 - $lower_rate);
  1641. }else{
  1642. $lower_price = ($bidinfos['demo_fee']/$consultinfos['num']+$bidinfos['delivery_fee']+$bidinfos['open_fee']/$consultinfos['num']+$bidinfos['cost_fee']*$bidinfos['good_weight']+$bidinfos['pakge_fee'] +$bidinfos['mark_fee']+ $bidinfos['cert_fee'])/ (1 - $lower_rate);
  1643. }
  1644. }
  1645. $info['cost_desc'] =$bidinfos['cost_desc'];
  1646. $info['work_day'] =$bidinfos['work_day'];
  1647. $info['delivery_day'] =$bidinfos['delivery_day'];
  1648. $info['expire_day'] =$bidinfos['expire_day'];
  1649. $info['origin_place'] =$bidinfos['origin_place'];
  1650. $info['origin_addr'] ="";
  1651. if($bidinfos['origin_place']!=''){
  1652. $code = explode(",",$bidinfos['origin_place']);
  1653. $temp=[];
  1654. $temp['provice_code']=isset($code[0])?$code[0]:"";
  1655. $temp['city_code']=isset($code[1])?$code[1]:"";
  1656. $temp['area_code']=isset($code[2])?$code[2]:"";
  1657. $addr= GetAddr(json_encode($temp));
  1658. $info['origin_addr'] = $addr;
  1659. }
  1660. $info['supplierNo'] =$bidinfos['supplierNo'];
  1661. $supplier = Db::name("supplier")->where(["code"=>$info['supplierNo']])->find();
  1662. $info['supplier_name'] = isset($supplier['name'])?$supplier['name']:"";
  1663. $info['pay_way'] =$bidinfos['pay_way'];
  1664. $info['tax'] =$bidinfos['tax'];
  1665. $info['send_way'] =$bidinfos['send_way'];
  1666. $info['metal_id'] =$bidinfos['metal_id'];
  1667. $info['is_gold_price'] =$bidinfos['is_gold_price'];
  1668. $info['config'] =$bidinfos['config'];
  1669. $info['other_config'] =$bidinfos['other_config'];
  1670. $info['weight'] =$bidinfos['weight'];
  1671. $info['good_weight'] =$bidinfos['good_weight'];
  1672. $info['is_diff'] =$bidinfos['is_diff'];
  1673. $info['demo_fee'] =$bidinfos['demo_fee'];
  1674. $info['delivery_fee'] =$bidinfos['delivery_fee'];
  1675. $info['open_fee'] =$bidinfos['open_fee'];
  1676. $info['pakge_fee'] =$bidinfos['pakge_fee'];
  1677. $info['nake_fee'] =$bidinfos['nake_fee'];
  1678. $info['mark_fee'] =$bidinfos['mark_fee'];
  1679. $info['cert_fee'] =$bidinfos['cert_fee'];
  1680. $info['cost_fee'] =$bidinfos['cost_fee'];
  1681. $info['total_fee'] =$bidinfos['total_fee'];
  1682. $info['supply_area'] =$bidinfos['supply_area'];
  1683. $info['remark'] =$bidinfos['remark'];
  1684. $info['is_addrs'] =$consultinfos['is_addrs'];
  1685. $info['is_custom'] =$consultinfos['is_custom'];
  1686. $info['metal_name']=isset($bidinfos['metal_id'])&& $bidinfos['metal_id']!=0?$this->noble[$bidinfos['metal_id']]:"";
  1687. // $info['sale_price'] =round($bidinfos['sale_price'],2);//议价前价格
  1688. $info['specinfo'] = isset($bidinfos['specinfo'])&&$bidinfos['specinfo']!=""?json_decode($bidinfos['specinfo'],true):[];
  1689. if($info['status']==7){
  1690. $info['lower_price'] =round($lower_price,2);
  1691. }
  1692. //获取议价原因
  1693. if ($info['result_info_id'] != 0) {
  1694. $info['result_info'] = Db::name('result_info')->where(['result_code' => $info['result_info_id'], 'type' => 7, 'status' => 1, 'is_del' => 0])->value('result');
  1695. } else {
  1696. $info['result_info'] = '';
  1697. }
  1698. return app_show(0,"获取成功",$info);
  1699. }
  1700. public function bidlist(){
  1701. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  1702. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  1703. $where=[['is_del',"=",0]];
  1704. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1705. if ($zxNo !== "") {
  1706. $where[] = ['zxNo','like','%'.$zxNo.'%'];
  1707. }
  1708. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  1709. if ($infoNo !== "") {
  1710. $where[] = ['infoNo','like','%'.$infoNo.'%'];
  1711. }
  1712. $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] !== "" ? trim($this->post['bidNo']) : "";
  1713. if ($bidNo !== "") {
  1714. $where[] = ['bidNo','like','%'.$bidNo.'%'];
  1715. }
  1716. $pgNo = isset($this->post['pgNo']) && $this->post['pgNo'] !== "" ? trim($this->post['pgNo']) : "";
  1717. if ($pgNo !== "") {
  1718. $bidinfo = Db::name("consult_info")->where([["pgNo","=",$pgNo],["is_del","=",0]])->column("infoNo");
  1719. $where[] = ['infoNo','in',$bidinfo];
  1720. }
  1721. $bargain_status = isset($this->post['bargain_status']) && $this->post['bargain_status'] !== "" ? intval($this->post['bargain_status']) : "";
  1722. if ($bargain_status !== "") {
  1723. $bidinfo = Db::name("consult_info")->where([["bargain_status","=",$bargain_status],["is_del","=",0]])->column("infoNo");
  1724. $where[] = ['infoNo','in',$bidinfo];
  1725. }
  1726. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  1727. if ($projectNo !== "") {
  1728. $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column
  1729. ("zxNo");
  1730. $where[] = ['zxNo','in',$zxlist];
  1731. }
  1732. $is_own = isset($this->post['is_own']) ? intval($this->post['is_own']) : "0";
  1733. if($is_own==1){
  1734. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  1735. if($token==""){
  1736. return error_show(101,'token不能为空');
  1737. }
  1738. $apply_id =GetUserInfo($token);
  1739. if(empty($apply_id)||$apply_id['code']!=0){
  1740. return error_show(1002,"申请人数据不存在");
  1741. }
  1742. $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  1743. $where[]=['createrid',"=",$rm];
  1744. }
  1745. $count = Db::name('consult_bids')->where($where)->count();
  1746. $total = ceil($count / $size);
  1747. $page = $page >= $total ? $total : $page;
  1748. $list =Db::name('consult_bids')->where($where)->page($page,$size)->select()->toArray();
  1749. $data=[];
  1750. foreach ($list as $value){
  1751. $catinfo = Db::name("cat")->where(["id"=>$value['cat_id']])->find();
  1752. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  1753. $unit =Db::name("unit")->where(["id"=>$value['unit_id']])->find();
  1754. $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1755. $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
  1756. $value['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  1757. if($value['brand_id']!=0){
  1758. $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  1759. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1760. }else{
  1761. $value["brand_name"]="";
  1762. $value["brand_id"]="";
  1763. }
  1764. $bidinfo = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
  1765. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1766. $god=[
  1767. "metal_id"=>$value['metal_id'],
  1768. "weight"=>$value["good_weight"],
  1769. "demo_fee"=>$value["demo_fee"],
  1770. "delivery_fee"=>$value["delivery_fee"],
  1771. "open_fee"=>$value["open_fee"],
  1772. "packing_fee"=>$value["pakge_fee"],
  1773. "mark_fee"=>$value["mark_fee"],
  1774. "nake_fee"=>$value["nake_fee"],
  1775. "cert_fee"=>$value["cert_fee"],
  1776. // "cost_fee"=>$value["cost_fee"],
  1777. "cost_fee"=>$value["sale_cost_fee"]!=$value['origin_cost_fee']? $value["sale_cost_fee"]: $value["cost_fee"],
  1778. //暂时注掉,搞不清楚原因@吴广广
  1779. "num"=>$bidinfo["num"],
  1780. ];
  1781. $top_cat = made($value['cat_id']);
  1782. $top_cat_id = isset($top_cat[0]['id'])?$top_cat[0]['id']:0;
  1783. if($value['is_gold_price']==1 && $top_cat_id==6 ){
  1784. $price = GoldPrice($god, $budget/100);
  1785. $value['sale_price'] = round($price,2);
  1786. $value['origin_price'] = $value["sale_cost_fee"]!=$value['origin_cost_fee']? $value["sale_price"]:
  1787. $value["origin_price"];
  1788. }
  1789. $value['cost_fee'] =$value['origin_cost_fee'];
  1790. $value['specinfo'] = json_decode($value['specinfo'],true);
  1791. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  1792. $value['bargain_status']=$bidinfo['bargain_status'];
  1793. //reject驳回原因,status==5表示驳回
  1794. $value['reject']=[];
  1795. if ($value['status'] >=5) {
  1796. $value['reject'] = Db::name('bargain_order')
  1797. ->field('id,remark,status')
  1798. ->where(['infoNo' => $infoNo, 'bidsNo' => $value['bidNo']])
  1799. ->whereIn('status', [3,8,11])->order("id desc")
  1800. ->find();
  1801. }
  1802. //产地
  1803. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  1804. if($value['delivery_place']!=""){
  1805. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$value['delivery_place']);
  1806. }
  1807. $value['delivery_place_cn']=GetAddr(json_encode($place));
  1808. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  1809. if($value['origin_place']!=""){
  1810. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$value['origin_place']);
  1811. }
  1812. $value['origin_addr']=GetAddr(json_encode($place));
  1813. // if($value['origin_place']!=''){
  1814. // $code = explode(",",$value['origin_place']);
  1815. // $temp=[];
  1816. // $temp['provice_code']=isset($code[0])?$code[0]:"";
  1817. // $temp['city_code']=isset($code[1])?$code[1]:"";
  1818. // $temp['area_code']=isset($code[2])?$code[2]:"";
  1819. // $addr= GetAddr(json_encode($temp));
  1820. // $value['origin_addr'] = $addr;
  1821. // }
  1822. $good_info = Db::name('good_basic')
  1823. ->field('id,createrid,creater')
  1824. ->where('is_del',0)
  1825. ->where('spuCode',$value['spuCode'])
  1826. ->findOrEmpty();
  1827. $value['good_createrid']=$good_info['createrid']??$value['createrid'];
  1828. $value['good_creater']=$good_info['creater']??$value['creater'];
  1829. $data[] = $value;
  1830. }
  1831. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  1832. }
  1833. public function feedlist(){
  1834. $where=[['is_del',"=",0]];
  1835. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1836. if ($zxNo !== "") {
  1837. $where[] = ['zxNo','=',$zxNo];
  1838. }
  1839. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  1840. if ($infoNo !== "") {
  1841. $where[] = ['infoNo','=',$infoNo];
  1842. }
  1843. $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] !== "" ? trim($this->post['bidNo']) : "";
  1844. if ($bidNo !== "") {
  1845. $where[] = ['bidNo','=',$bidNo];
  1846. }
  1847. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  1848. if ($projectNo !== "") {
  1849. $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column
  1850. ("zxNo");
  1851. $where[] = ['zxNo','in',$zxlist];
  1852. }
  1853. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1854. if($token==''){
  1855. return error_show(102,"参数token不能为空");
  1856. }
  1857. $is_own = isset($this->post['is_own']) ? intval($this->post['is_own']) : "0";
  1858. if($is_own==1){
  1859. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  1860. if($token==""){
  1861. return error_show(101,'token不能为空');
  1862. }
  1863. $apply_id =GetUserInfo($token);
  1864. if(empty($apply_id)||$apply_id['code']!=0){
  1865. return error_show(1002,"申请人数据不存在");
  1866. }
  1867. $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  1868. $where[]=['createrid',"=",$rm];
  1869. }
  1870. $list =Db::name('consult_bids')->where($where)->select();
  1871. $data=[];
  1872. foreach ($list as $value){
  1873. $catinfo = Db::name("cat")->where(["id"=>$value['cat_id']])->find();
  1874. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  1875. $unit =Db::name("unit")->where(["id"=>$value['unit_id']])->find();
  1876. $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1877. $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
  1878. $value['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  1879. if($value['brand_id']!=0){
  1880. $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  1881. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1882. }else{
  1883. $value["brand_name"]="";
  1884. $value["brand_id"]="";
  1885. }
  1886. $bidinfo = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
  1887. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1888. $god=[
  1889. "metal_id"=>$value['metal_id'],
  1890. "weight"=>$value["good_weight"],
  1891. "demo_fee"=>$value["demo_fee"],
  1892. "delivery_fee"=>$value["delivery_fee"],
  1893. "open_fee"=>$value["open_fee"],
  1894. "packing_fee"=>$value["pakge_fee"],
  1895. "mark_fee"=>$value["mark_fee"],
  1896. "nake_fee"=>$value["nake_fee"],
  1897. "cert_fee"=>$value["cert_fee"],
  1898. "cost_fee"=>$value["cost_fee"],
  1899. "num"=>$bidinfo["num"],
  1900. ];
  1901. if ($value['is_gold_price'] == 1 ) {
  1902. $gold = Db::name("gold_price1")->where(["type"=>$value['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1903. ->find();
  1904. //$total_fee(成本合计初始价格) =打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价0+运费;
  1905. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  1906. $saleprice = ($value['demo_fee']/$bidinfo['num']+$value['delivery_fee']+$value["open_fee"]/$bidinfo['num'] +$value["good_weight"] *$gold["price"] +
  1907. $value["cost_fee"] * $value["good_weight"] + $value["pakge_fee"]+ $value["mark_fee"] +$value["cert_fee"] +$value["nake_fee"]) / (1 - $budget);
  1908. // //销售工艺费=((开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100)-(打样费/购买数量 + 开模费/购买数量 +包装费+加标费+证书费+产品裸价0+运费) )/商品重量-最新金价
  1909. // $sale_cost_fee = (($open_fee / $zxinfo['num'] + $weight * $gold["price"] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee) / (1 - $budget) - ($demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee)) / $weight - $gold["price"];
  1910. }else{
  1911. if($value["nake_fee"]){
  1912. $saleprice = ($value['demo_fee']/$bidinfo['num']+$value['delivery_fee']+$value["open_fee"]/$bidinfo['num']+$value["cost_fee"] * $value["good_weight"]+ $value["pakge_fee"]+ $value["mark_fee"] +$value["cert_fee"] +$value["nake_fee"])/ (1 - $budget);
  1913. }else{
  1914. $saleprice = ($value['demo_fee']/$bidinfo['num']+$value['delivery_fee']+$value["open_fee"]/$bidinfo['num']+$value["cost_fee"] * $value["good_weight"]+ $value["pakge_fee"]+ $value["mark_fee"] +$value["cert_fee"] +$value["nake_fee"]) /
  1915. (1 - $budget);
  1916. }
  1917. }
  1918. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  1919. $value['specinfo'] = json_decode($value['specinfo'],true);
  1920. $value['bargain_status']=$bidinfo['bargain_status'];
  1921. $data[]=$value;
  1922. }
  1923. return app_show(0,"获取成功",$data);
  1924. }
  1925. public function bragain_list(){
  1926. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  1927. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  1928. $where=[['bo.is_del',"=",0]];
  1929. $bidsNo = isset($this->post['bidsNo'])&&$this->post['bidsNo']!=""?trim($this->post['bidsNo']):"";
  1930. if($bidsNo!=""){
  1931. $where[]=["bo.bidsNo","like","%$bidsNo%"];
  1932. }
  1933. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1934. if ($zxNo !== "") {
  1935. $where[] = ['bo.zxNo','like',"%$zxNo%"];
  1936. }
  1937. $bargainNo = isset($this->post['bargainNo']) && $this->post['bargainNo'] !== "" ? trim($this->post['bargainNo']) : "";
  1938. if ($bargainNo !== "") {
  1939. $where[] = ['bo.bargainNo','like',"%$bargainNo%"];
  1940. }
  1941. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  1942. if ($status!== "") {
  1943. $where[] = ['bo.status','=',$status];
  1944. }
  1945. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  1946. if ($infoNo !== "") {
  1947. $where[] = ['bo.infoNo','like',"%$infoNo%"];
  1948. }
  1949. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  1950. if ($projectNo !== "") {
  1951. $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column("zxNo");
  1952. $where[] = ['bo.zxNo','in',$zxlist];
  1953. }
  1954. $pgNo = isset($this->post['pgNo']) && $this->post['pgNo'] !== "" ? trim($this->post['pgNo']) : "";
  1955. if ($pgNo !== "") {
  1956. $bidinfo = Db::name("consult_info")->where([["pgNo","=",$pgNo],["is_del","=",0]])->column("infoNo");
  1957. $where[] = ['bo.infoNo','in',$bidinfo];
  1958. }
  1959. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start'] : "";
  1960. $end= isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] : "";
  1961. if($start!=""){
  1962. $where[]=["bo.addtime",">=",date("Y-m-d H:i:s",strtotime($start))];
  1963. }
  1964. if($end!=""){
  1965. $where[]=["bo.addtime","<=",date("Y-m-d H:i:s",strtotime($end))];
  1966. }
  1967. $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  1968. if ($company_name !== "") $where[] = ["bo.createrid", 'in', get_company_item_user_by_name($company_name)];
  1969. // $role=$this->checkRole();
  1970. // if(!empty($role['write'])){
  1971. // $where[]=["bo.createrid","in",$role['write']];
  1972. // }
  1973. $role = $this->checkDataShare();
  1974. if (!empty($role[DataGroupModel::$type_全部])) $where[] = ['bo.createrid', 'in', $role[DataGroupModel::$type_全部]];
  1975. $count=Db::name("bargain_order")
  1976. ->alias('bo')
  1977. ->leftJoin("depart_user u", "u.uid=bo.createrid AND u.is_del=0")
  1978. ->where($where)
  1979. ->count();
  1980. $total = ceil($count / $size);
  1981. $page = $page >= $total ? $total : $page;
  1982. $list = Db::name('bargain_order')
  1983. ->alias('bo')
  1984. ->field('bo.*,u.itemid')
  1985. ->leftJoin("depart_user u", "u.uid=bo.createrid AND u.is_del=0")
  1986. ->where($where)
  1987. ->page($page, $size)
  1988. ->order('bo.addtime', 'desc')
  1989. ->cursor();
  1990. $data=[];
  1991. foreach ($list as $value){
  1992. $bidinfos = Db::name("consult_bids")->where([["bidNo","=",$value['bidsNo']],["is_del","=",0]])->find();
  1993. $value['spuCode'] = isset($bidinfos['spuCode'])?$bidinfos['spuCode']:"";
  1994. $value['good_name'] = isset($bidinfos['good_name'])?$bidinfos['good_name']:"";
  1995. $value['good_img'] = isset($bidinfos['good_img'])?$bidinfos['good_img']:"";
  1996. $value['brand_id'] = isset($bidinfos['brand_id'])?$bidinfos['brand_id']:"";
  1997. if($bidinfos['brand_id']!=0){
  1998. $value['brand_id'] = $bidinfos['brand_id'];
  1999. $brand=Db::name("brand")->where(["id"=>$bidinfos['brand_id']])->find();
  2000. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  2001. }else{
  2002. $value["brand_name"]="";
  2003. $value["brand_id"]="";
  2004. }
  2005. $catinfo = Db::name("cat")->where(["id"=>$bidinfos['cat_id']])->find();
  2006. $value['can']= isset($bidinfos['cat_id']) && $bidinfos['cat_id'] !=0 ? made($bidinfos['cat_id']):[];
  2007. $unit =Db::name("unit")->where(["id"=>$bidinfos['unit_id']])->find();
  2008. $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
  2009. $bidinfoe = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
  2010. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  2011. $value['budget'] =$budget;
  2012. $god=[
  2013. "metal_id"=>$bidinfos['metal_id'],
  2014. "weight"=>$bidinfos["good_weight"],
  2015. "demo_fee"=>$bidinfos["demo_fee"],
  2016. "delivery_fee"=>$bidinfos["delivery_fee"],
  2017. "open_fee"=>$bidinfos["open_fee"],
  2018. "packing_fee"=>$bidinfos["pakge_fee"],
  2019. "mark_fee"=>$bidinfos["mark_fee"],
  2020. "nake_fee"=>$bidinfos["nake_fee"],
  2021. "cert_fee"=>$bidinfos["cert_fee"],
  2022. "cost_fee"=>$bidinfos["cost_fee"],
  2023. "num"=>$bidinfoe["num"],
  2024. ];
  2025. // if($bidinfos['is_gold_price']==1){
  2026. // $price = GoldPrice($god, $budget/100);
  2027. // }else{
  2028. // $price = GoodPrice($god, $budget/100);
  2029. // }
  2030. $value['metal_name']=isset($bidinfos['metal_id'])&& $bidinfos['metal_id']!=0?$this->noble[$bidinfos['metal_id']]:"";
  2031. $value['sale_price'] =round($bidinfos['origin_price'],2);
  2032. $value['cost_before_price'] =round($bidinfos['origin_cost_fee'],2);
  2033. $value['specinfo'] = isset($bidinfos['specinfo'])&&$bidinfos['specinfo']!=""?json_decode($bidinfos['specinfo'],true):[];
  2034. $value['company_name'] = implode('/', array_column(GetPart($value['itemid']), 'name'));
  2035. //是否具有编辑权限
  2036. $value['is_allow_update'] = 0;
  2037. if (in_array($this->roleid, [1, 33]) || in_array($value['createrid'], $role[DataGroupModel::$type_可编辑])) $value['is_allow_update'] = 1;
  2038. $data[]=$value;
  2039. }
  2040. return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
  2041. }
  2042. public function crontablist(){
  2043. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  2044. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  2045. $where=[['a.is_del',"=",0],['b.is_del',"=",0]];
  2046. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  2047. if ($zxNo !== "") {
  2048. $where[] = ['a.zxNo','=',$zxNo];
  2049. }
  2050. $salesman = isset($this->post['salesman']) && $this->post['salesman'] !== "" ? trim($this->post['salesman']) : "";
  2051. if ($salesman !== "") {
  2052. //$where["salesman"] =Db::Raw("like '%$salesman%'");
  2053. $where[]= ["b.salesman",'like',"%$salesman%"];
  2054. }
  2055. $cpName = isset($this->post['cpName']) && $this->post['cpName'] !== "" ? trim($this->post['cpName']) : "";
  2056. if ($cpName !== "") {
  2057. //$where["cpName"]= Db::Raw("like '%$cpName%'");
  2058. $where[]= ["a.good_Name",'like',"%$cpName%"];
  2059. }
  2060. $khNo = isset($this->post['khNo']) && $this->post['khNo'] !== "" ? trim($this->post['khNo']) : "";
  2061. if ($khNo !== "") {
  2062. // $where['khNo'] = $khNo;
  2063. $where[]= ["b.khNo",'like',"%$khNo%"];
  2064. }
  2065. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
  2066. if ($start !="") {
  2067. //$where = ["zxtime"=>Db::raw(">= '{$start}'")];
  2068. $where[]= ["a.addtime",'>=',$start];
  2069. }
  2070. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
  2071. if($end !=""){
  2072. $where[]= ["a.addtime",'<=',$end];
  2073. }
  2074. $status = isset($this->post['status']) && $this->post['status'] !== "" ? trim($this->post['status']) : "";
  2075. if ($status !== "") {
  2076. $where[]= ["a.status",'=',$status];
  2077. }
  2078. // $role=$this->checkRole();
  2079. // if(!empty($role['platform']) ){
  2080. // $where[]=["b.platform_code","in",$role['platform']];
  2081. // }
  2082. $count = Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)
  2083. ->count();
  2084. $total = ceil($count / $size);
  2085. $page = $page >= $total ? $total : $page;
  2086. $list =Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)->page($page,$size)
  2087. ->field("a.*,b.createrid,b.creater,b.is_project,b.projectNo,b.khNo,b.endtime,b.platform_code,b.saleid,b.salesman,b.depart")->select();
  2088. $data=[];
  2089. foreach ($list as $value){
  2090. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  2091. $cat =Db::name("cat")->where(["id"=>$value['cat_id']])->find();
  2092. $budget = isset($cat['order_rate']) ? $cat['order_rate']:0;
  2093. $value['original_price']=sprintf("%.2f",$value['budget_price']* (1 -$budget/100));
  2094. $brand = Db::name("brand")->where(['id'=>$value['brand_id']])->find();
  2095. $value['brand_name']= isset($brand['brand_name']) && $brand['brand_name']!='' ? $brand['brand_name']:"";
  2096. $value['khname']="";
  2097. $value['specinfo']=isset($value['specinfo'])&&$value['specinfo']!=""? json_decode($value['specinfo'],
  2098. true):[];
  2099. if($value['khNo']!==""){
  2100. $kh=Db::name("customer_info")->where(['companyNo'=>$value['khNo']])->find();
  2101. $value['khname']= isset($kh['companyName'])?$kh['companyName']:"";
  2102. }
  2103. $consult =Db::name("consult_bids")->where(["infoNo"=>$value['infoNo'],"createrid"=>$this->uid,"is_del"=>0])
  2104. ->find();
  2105. $consults =Db::name("consult_bids")->where(["infoNo"=>$value['infoNo'],"is_del"=>0])->find();
  2106. $value['is_feed'] =$consult==false?0:1;
  2107. $value['is_all_feed'] =$consults==false?0:1;
  2108. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  2109. $data[]=$value;
  2110. }
  2111. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  2112. }
  2113. //复制上面的bidlist方法,只更改排序方式
  2114. public function bidlistCopy()
  2115. {
  2116. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
  2117. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
  2118. $where = [['cb.is_del', "=", 0],['c.status','<>',6]];//不要'取消转单'状态下的数据
  2119. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  2120. if ($zxNo !== "") $where[] = ['cb.zxNo', 'like', '%' . $zxNo . '%'];
  2121. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  2122. if ($infoNo !== "") $where[] = ['cb.infoNo', 'like', '%' . $infoNo . '%'];
  2123. $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] !== "" ? trim($this->post['bidNo']) : "";
  2124. if ($bidNo !== "") $where[] = ['cb.bidNo', 'like', '%' . $bidNo . '%'];
  2125. $pgNo = isset($this->post['pgNo']) && $this->post['pgNo'] !== "" ? trim($this->post['pgNo']) : "";
  2126. if ($pgNo !== "") {
  2127. $bidinfo = Db::name("consult_info")->where([["pgNo", "=", $pgNo], ["is_del", "=", 0]])->column("infoNo");
  2128. $where[] = ['cb.infoNo', 'in', $bidinfo];
  2129. }
  2130. $bargain_status = isset($this->post['bargain_status']) && $this->post['bargain_status'] !== "" ? intval($this->post['bargain_status']) : "";
  2131. if ($bargain_status !== "") {
  2132. $bidinfo = Db::name("consult_info")->where([["bargain_status", "=", $bargain_status], ["is_del", "=", 0]])->column("infoNo");
  2133. $where[] = ['cb.infoNo', 'in', $bidinfo];
  2134. }
  2135. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  2136. if ($projectNo !== "") {
  2137. $zxlist = Db::name("consult_order")->where(["projectNo" => $projectNo, "is_del" => 0, "is_project" => 1])->column("zxNo");
  2138. $where[] = ['cb.zxNo', 'in', $zxlist];
  2139. }
  2140. $is_own = isset($this->post['is_own']) ? intval($this->post['is_own']) : "0";
  2141. if ($is_own == 1) {
  2142. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  2143. if ($token == "") return error_show(101, 'token不能为空');
  2144. $apply_id = GetUserInfo($token);
  2145. if (empty($apply_id) || $apply_id['code'] != 0) return error_show(1002, "申请人数据不存在");
  2146. $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  2147. $where[] = ['cb.createrid', "=", $rm];
  2148. }
  2149. $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  2150. if ($company_name !== "") $where[] = ["cb.createrid", 'in', get_company_item_user_by_name($company_name)];
  2151. $good_name = isset($this->post['good_name']) && $this->post['good_name'] !== "" ? trim($this->post['good_name']) : "";
  2152. if ($good_name !== "") $where[] = ["cb.good_name", 'like', '%' . $good_name . '%'];
  2153. $supplierName = isset($this->post['supplierName']) && $this->post['supplierName'] !== "" ? trim($this->post['supplierName']) : "";
  2154. if ($supplierName !== "") $where[] = ["s.name", 'like', '%' . $supplierName . '%'];
  2155. $count = Db::name('consult_bids')
  2156. ->alias('cb')
  2157. ->leftJoin("depart_user u", "u.uid=cb.createrid AND u.is_del=0")
  2158. ->leftJoin("consult_info c", "c.infoNo=cb.infoNo")
  2159. ->leftJoin('supplier s', 's.code=cb.supplierNo')
  2160. ->where($where)
  2161. ->count();
  2162. $total = ceil($count / $size);
  2163. $page = $page >= $total ? $total : $page;
  2164. $list = Db::name('consult_bids')
  2165. ->alias('cb')
  2166. ->field('cb.*,u.itemid,s.name supplierName')
  2167. ->leftJoin("depart_user u", "u.uid=cb.createrid AND u.is_del=0")
  2168. ->leftJoin("consult_info c", "c.infoNo=cb.infoNo")
  2169. ->leftJoin('supplier s', 's.code=cb.supplierNo')
  2170. ->where($where)
  2171. ->page($page, $size)
  2172. ->order('cb.addtime', 'desc')
  2173. ->cursor();
  2174. $data = [];
  2175. foreach ($list as $value) {
  2176. $catinfo = Db::name("cat")->where(["id" => $value['cat_id']])->find();
  2177. $value['can'] = isset($value['cat_id']) && $value['cat_id'] != 0 ? made($value['cat_id']) : [];
  2178. $unit = Db::name("unit")->where(["id" => $value['unit_id']])->find();
  2179. $value['unit'] = isset($unit['unit']) ? $unit['unit'] : '';
  2180. // $supplier = Db::name("supplier")->where(["code" => $value['supplierNo']])->find();
  2181. // $value['supplierName'] = isset($supplier['name']) ? $supplier['name'] : "";
  2182. if ($value['brand_id'] != 0) {
  2183. $brand = Db::name("brand")->where(["id" => $value['brand_id']])->find();
  2184. $value["brand_name"] = isset($brand['brand_name']) ? $brand['brand_name'] : "";
  2185. } else {
  2186. $value["brand_name"] = "";
  2187. $value["brand_id"] = "";
  2188. }
  2189. $bidinfo = Db::name("consult_info")->where(["infoNo" => $value["infoNo"]])->find();
  2190. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate'] : 0;
  2191. $god = [
  2192. "metal_id" => $value['metal_id'],
  2193. "weight" => $value["good_weight"],
  2194. "demo_fee" => $value["demo_fee"],
  2195. "delivery_fee" => $value["delivery_fee"],
  2196. "open_fee" => $value["open_fee"],
  2197. "packing_fee" => $value["pakge_fee"],
  2198. "mark_fee" => $value["mark_fee"],
  2199. "nake_fee" => $value["nake_fee"],
  2200. "cert_fee" => $value["cert_fee"],
  2201. "cost_fee" => $value["sale_cost_fee"]!=$value["origin_cost_fee"] ? $value["sale_cost_fee"] : $value["cost_fee"],
  2202. "num" => $bidinfo["num"],
  2203. ];
  2204. if ($value['is_gold_price'] == 1) {
  2205. $price = GoldPrice($god, $budget / 100);
  2206. $value['sale_price'] = round($price, 2);
  2207. }
  2208. $value['cost_fee'] = $value['origin_cost_fee'];
  2209. $value['specinfo'] = json_decode($value['specinfo'], true);
  2210. $value['metal_name'] = isset($value['metal_id']) && $value['metal_id'] != 0 ? $this->noble[$value['metal_id']] : "";
  2211. $value['bargain_status'] = $bidinfo['bargain_status'];
  2212. //reject驳回原因,status==5表示驳回
  2213. $value['reject'] = [];
  2214. if ($value['status'] >= 5) {
  2215. $value['reject'] = Db::name('bargain_order')
  2216. ->field('id,remark,status')
  2217. ->where(['infoNo' => $infoNo, 'bidsNo' => $value['bidNo']])
  2218. ->whereIn('status', [3, 8, 11])->order("id desc")
  2219. ->find();
  2220. }
  2221. //产地
  2222. $place = ["provice_code" => "", "city_code" => "", "area_code" => ""];
  2223. if ($value['delivery_place'] != "") {
  2224. list($place['provice_code'], $place['city_code'], $place['area_code']) = explode(",", $value['delivery_place']);
  2225. }
  2226. $value['delivery_place_cn'] = GetAddr(json_encode($place));
  2227. $place = ["provice_code" => "", "city_code" => "", "area_code" => ""];
  2228. if ($value['origin_place'] != "") {
  2229. list($place['provice_code'], $place['city_code'], $place['area_code']) = explode(",", $value['origin_place']);
  2230. }
  2231. $value['origin_addr'] = GetAddr(json_encode($place));
  2232. // if($value['origin_place']!=''){
  2233. // $code = explode(",",$value['origin_place']);
  2234. // $temp=[];
  2235. // $temp['provice_code']=isset($code[0])?$code[0]:"";
  2236. // $temp['city_code']=isset($code[1])?$code[1]:"";
  2237. // $temp['area_code']=isset($code[2])?$code[2]:"";
  2238. // $addr= GetAddr(json_encode($temp));
  2239. // $value['origin_addr'] = $addr;
  2240. // }
  2241. $value['company_name'] = implode('/', array_column(GetPart($value['itemid']), 'name'));
  2242. $data[] = $value;
  2243. }
  2244. return app_show(0, "获取成功", ['count' => $count, 'list' => $data]);
  2245. }
  2246. }